[CakePHP]How To Call Controller Action or Controller Function From Views Or Any Location
Posted by in CakePHPHi Friends, While developing cakePHP web application we get so many problems and difficulties. Some days ago i got one problem in which I wanted to call controller action or controller function from view file. We can’t directly call controller function in view file. So I have found one function in cakePHP by which we can call any controller method/action/function from any location in cakePHP or from view.
requestAction function calls a controller’s action from any location and returns data from the action. See below :
$clientdata=$this->requestAction('/clients/get_client_data/'.$clientid);
Above is code by which you can call controller method/action/function get_client_data from any location or view files. If you use above code it means you are calling client controller and calling get_client_data of client controller. Also you can see that I have passed $clientid with URL, $clientid is dynamic client id which we can passed automatically inside for loop to get client data evertime for loop runs.
When this function calls in view it execute get_client_data function and then return result from get_client_data function in $clientdata variable. In this way we can call controller function from any location or from view.
You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.




