第1版:当我的目录是www/cake/cake2.1/app时,它运行良好,但当它的www/cake/app时我面临以下问题。
嗨,我刚开始用蛋糕php做博客教程。我正在尝试创建一个表单并将值存储在数据库中,就像我遵循的教程中的所有步骤一样。
问题是值被存储到Db中,但我被重定向到一个空白页面。
控制器:
<?php
class PostsController extends AppController {
public $helpers = array('Html', 'Form');
public function index(){
$this->set('posts', $this->Post->find('all'));
}
function view($id = null) {
$this->Post->id = $id;
$this->set('post', $this->Post->read());
}
function add(){
if($this->request->is('post')){
if($this->Post->save($this->request->data)){
$this->Session->setFlash('Your post has been saved.');
$this->redirect(array('action'=>'index'));
}else{
$this->Session->setFlash('Unable to add your post.');
}
}
}
}
重定向没有正确进行,它显示了一个带有url的空白页面hxxp://localhost/cake/posts/add
即使试过$this->redirect('http://www.google.com');
也没用,伙计们?
后模型:
<?php
class Post extends AppModel {
public $validate = array(
'title' => array(
'rule' => 'notEmpty'
),
'body' => array(
'rule' => 'notEmpty'
)
);
}
这可能是由于文件末尾的空白
请检查您的文件"?>"后是否有空白标记它重定向到空白页
或者您可以删除"?>'(关闭php标记)以删除此问题。
答案发现:zip提取不正确,我所做的只是再次提取zip文件,然后运行我的代码并欢呼。。。它运行良好
您有语法错误。在add()
方法的末尾有两个闭合的}
。拆下一个,应该没问题。
同样值得关注的是/app/tmp/log/error.log
的错误日志,它会提醒您此类错误。