Reputation: 1927
I'm posting a specific value through a POST form to my CakePHP app. Within the AppController I handle this specific POST data and afterwards I unset $this->request->data, e.g.
if(!empty($this->request->data['Keyboard'])) {
$this->Session->write('Keyboard.active', $this->request->data['Keyboard']['active']);
unset($this->request->data);
}
Afterwards I want ALL request data to be unset (hence the $this->request->data
). Within my child controllers I call parent::beforefilter();
as the first line of code in its respective beforeFilter
function, making sure the beforeFilter
of my appController
is initiated. However, in my childController the following line of code will still evaluate to true:
if($this-request->is('post'))
How do I 'unset' the is('post') call? I've also tried $this->request->is('post') = false
in the if-statement
above, with no success however.
Upvotes: 0
Views: 3040
Reputation: 4522
The "problem" with $this->request->is($anything)
(in your case at least) is that it is just a function to compare variables, not a setter.
Here's the API code in case you want to check it out.
So, basically, this code compares the variable env('REQUEST_METHOD')
to POST
(that's in the detectors part of the code).
There's no way a $this->request->is('post') = false
is going to work. Something like
$_ENV["REQUEST_METHOD"] = null;
//or
unset($_ENV["REQUEST_METHOD"]);
after you unset the request data might work, but I don't guarantee anything because I haven't tried it.
I feel this approach is very dirty, I don't like to mess with those variables at all if there's no function already available for it, but I expect you to have considered all possible choices to avoid messing with the request
already and see this as the only solution. Otherwise you should post another question addressing this subject and see if better approaches come up.
Hopes it helps in your case.
Upvotes: 1