【发布时间】:2013-04-10 23:47:31
【问题描述】:
在添加管理员前缀/路由之前,一切正常...
目前,我有一个 QuestionsController.php 文件,其功能如下:
public function admin_add() {
if ($this->request->is('post') ) {
$this->Question->create();
if ($this->Question->save($this->request->data)) {
$this->Session->setFlash('Your question has been saved.');
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash('Unable to add your question.');
}
} else {
$this->Session->setFlash('Not post.');
}
}
这里是/views/Questions/admin_add.php的内容:
<h2>Add a question</h2>
<?php
echo $this->Form->create('Question');
echo $this->Form->input('nickname');
echo $this->Form->input('content');
echo $this->Form->input('option1');
echo $this->Form->input('option2');
echo $this->Form->input('option3');
echo $this->Form->end('Save question');
echo $this->Html->link('Cancel', array('controller' => 'questions', 'action' => 'index'));
注意到控制器底部的 setFlash("Not post.") 了吗?每次单击“保存问题”按钮时,我都会看到该消息?为什么?
更新
我们已经确定请求方法是get,这就解释了为什么它不起作用。但现在真正的问题是为什么是get。我很确定在添加管理员前缀之前是post。
【问题讨论】:
-
暂时,你可以检查一下
if(!empty($this->request->data)) {- 虽然这并不能回答你关于为什么的问题。 -
你的表单方法是 POST 吗?
-
@Dave 好主意!
$this->request->data实际上是空的。知道为什么吗? -
@BarryChapman 我是这么认为的,但它不起作用的事实表明并非如此。
-
您使用的是管理员前缀,对吗?而不是管理员路由?
标签: php cakephp cakephp-2.0