CakePHP 2.0检测请求类型表现奇怪

Wil*_*ill 4 cakephp cakephp-2.0

看看这段代码:

   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);
    }
Run Code Online (Sandbox Code Playgroud)

当我在此操作的相应视图中提交表单时,$ this-> request-> is('post')似乎返回false.运行if/else语句的另一端.这是奇怪的一点 - POST数据就在那里,我对调试的调用($ this-> request-> data)吐出了我期待的数据!

这是传递的数据:

Array
(
[Profile] => Array
    (
        [aboutMe] => Hey there
    )

[Permission] => Array
    (
        [Profile] => Array
            (
                [aboutMe] => 1
            )

    )

)
Run Code Online (Sandbox Code Playgroud)

现在,我当然可以将$ this-> request-> is('post')更改为!empty($ this-> request-> data),但这不会解决问题.

那么我的代码有什么问题吗?这是怎么回事?

谢谢!

小智 13

试试这个:

if ($this->request->is('post') || $this->request->is('put'))

http://cakephp.lighthouseapp.com/projects/42648/tickets/2353