Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP 2.0 detecting request type is behaving oddly

Take a look at this code:

   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);
    }

When I submit the form in the corresponding view for this action, it appears that $this->request->is('post') returns false. The other end of the if/else statement is run. Here's the weird bit - the POST data is there, and my call to debug($this->request->data) spits out the data I am expecting!

Here's the data that gets passed:

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

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

    )

)

Now, I could of course just change $this->request->is('post') to !empty($this->request->data) but that would not be grappling the problem head on.

So is anything wrong with my code? What's going on?

Thanks!

like image 749
Will Avatar asked Dec 10 '22 03:12

Will


1 Answers

Try using this:

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

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

like image 118
Wylie Avatar answered Feb 12 '23 03:02

Wylie