I'm on CakePHP v2.4.
In a model's afterSave()
callback, I want to do something conditionally, depending on conditions of the request. However $this->request
does not seem to be defined here:
public function afterSave( $created, $options=array() ) {
$this->log( $this->request ); //NOTHING HERE
}
How do I do this?
In CakePHP 2.0 this appears to have changed. According to the documentation you can access $this->request->query or $this->request['url'] .
You can retrieve post data as Array. $post_data= $this->request->data; You can retrieve post data for particular key.
The request and response objects provide an abstraction around HTTP requests and responses. The request object in CakePHP allows you to introspect an incoming request, while the response object allows you to effortlessly create HTTP responses from your controllers.
You can access it via the global Router class.
public function afterSave( $created, $options=array() ) {
$this->log( Router::getRequest() );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With