Hi guys, today I’m going to show you how to access or get CakePHP’s current page controller, action and parameters. I found this useful when high lighting certain elements of a page for example are tabs, sidebars, etc. that tells the user what part of the system or website they are currently in.
For instance we will have the following URL:
Based on that URL, our controller is users. To access it we will have:
$current_controller = $this->params[‘controller’];
Our action is edit and we will access it this way:
$current_action = $this->action;
Our first parameter is 27, which is the ID of the record to be edited. We can access it by doing:
$user_id = $this->params[‘pass’];
In case that we have second parameter, we have to access it this way:
$second_parameter = $this->params[‘pass’];
For the third parameter:
$third_parameter = $this->params[‘pass’];
and so on…
You can do these codes either in your controller or view files.