【发布时间】:2012-02-19 13:47:33
【问题描述】:
看看这段代码:
if ($this->request->is('post')){
$this->request->data['Profile']['userId'] = $this->Auth->user('id');
if ($this->Profile->save($this->request->data)){
$this->Profile->setPermissions($this->Profile->id, $this->request->data['Permission']);
$this->NFSSession->setSuccessMessage('Your profile has been updated.');
}else{
$this->NFSSession->setSuccessMessage('There was a problem updating your profile. Please try again.');
}
}else{
echo 'Not a post request!!?!?!?!?!';
debug($this->request->data);
}
当我在此操作的相应视图中提交表单时,似乎 $this->request->is('post') 返回 false。 if/else 语句的另一端运行。这是奇怪的一点 - POST 数据在那里,我对 debug($this->request->data) 的调用吐出了我期待的数据!
这是传递的数据:
Array
(
[Profile] => Array
(
[aboutMe] => Hey there
)
[Permission] => Array
(
[Profile] => Array
(
[aboutMe] => 1
)
)
)
现在,我当然可以将 $this->request->is('post') 更改为 !empty($this->request->data) 但这不会直接解决问题。
那么我的代码有什么问题吗?怎么回事?
谢谢!
【问题讨论】:
-
您的视图是什么样的?特别是您提交的表单。
-
它生成上述 POST 数据 - 当然这是关于视图的唯一相关信息(如果我遗漏了什么,请道歉)?
标签: cakephp cakephp-2.0