之前添加管理员前缀/路由,一切工作正常...CakePHP的:“添加”操作不会以管理员前缀工作
目前,我有一个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( “不发布”。)在控制器的底部?每次点击“保存问题”按钮,我都会看到该消息?为什么?
UPDATE 我们已经确定请求方法是get
,这说明了它不起作用的原因。但现在真正的问题是为什么是get
。在添加管理员前缀之前,我确定它是post
。
临时,你可以检查'如果(空($这个 - >请求 - >数据)!){' - 尽管这不回答你的问题,为什么。 – Dave 2013-04-10 23:53:51
是你的表单方法POST吗? – 2013-04-10 23:58:20
@Dave好主意! '$ this-> request-> data'实际上是空的。任何想法为什么? – emersonthis 2013-04-10 23:58:32