热搜:NVER node 开发 php

cakephp部署在sae上遇到的跳转问题

2024-09-19 14:05:01
cakephp部署在sae上遇到的跳转问题

本帖最后由 jianghu52 于 2013-07-26 11:25:41 编辑

sae cakephp 跳转

在sae上部署了cakephp,结果我连基础的跳转都没搞定,真心失败啊。只好来这里求教了。
我在本地实验了一下相同的代码,是好用的,但是部署到sae上就不行了。代码片段如下
AppController.php:
AppController extends Controller {        public function beforeFilter() {        parent::beforeFilter();        $current_ctl = strtolower($this->name);                if($current_ctl === 'pages'){            //在这里echo的打断点的话,sae里面也可以正常显示            $this->redirect(array('controller' => 'test', 'action' => 'index'));                   }    }}


TestController.php:
class TestController extends AppController {    var $name = 'test';    var $uses = Array('');    public function index() {        /*这里echo打断点已经没用了,初步怀疑是大小写问题,但是我实验过了很多中,比如文件名带下划线,不带下划线,首字母大写,小写。name名改成Test,以及声明name用public的都无效*/        $this->set('CN', '中文测试');    }}


index.ctp:

<?php echo $CN; ?>



在本机上正常显示,但是sae上就一片空白。不知道为什么。真心奇怪啊。


回复讨论(解决方案)

你这个框架要写盘的吗?如果要就不能用的

我明白你的意思,因为默认的cakephp是要写app的tmp文件的,但是sae不支持写文件的,所以如果什么不改就移植的话,会出现问题。我移植了一个版本,将cake要写的文件都写在了Memcache里面了。因此可以跑通。
我已经将代码上传到了github上了
https://github.com/jianghu52/sae_cakephp_sample。这个包如果直接上传到sae上就可以打开home页面。但是问题就是。我没有办法实现跳转
我在pagecontroller里写了一句跳转方法【$this->redirect(array('controller' => 'test', 'action' => 'index'));】。在sae上的表现形式是地址栏可以显示【http://**.sinaapp.com/test】。页面报错为【The requested URL /test was not found on this server.】。也就是说我写的controller没有被解析。不知道问题出在哪里。

研究了半天,终于搞明白一件事。就是我对sae本身的文件系统不够了解。
给的原来的框架里面,只有sae_app_wizard.xml,而不存在config.yaml文件,因此,redirect的跳转依然是向app里的tmp包请求内容,不能成功。添加了config.yaml文件,在里面加这样两句

handle:  - rewrite:if (!is_file() && !is_dir() && path ~ "^app/webroot/(.*)") goto "app/webroot/index.php?url=$1&%{QUERY_STRING}"  - rewrite:if (!is_file() && !is_dir() && path ~ "(.*)") goto "app/webroot/$1?%{QUERY_STRING}"

就可以实现跳转了。