Cakephp 3.6 : Extract a value from the url

Hello guys, i struggle to extract a value from the URL of a page here is the URL :
http://localhost/projet-1a2a-gestion-des-fiches-de-suivi-licence-pro/cakephp/users/editpass/15

i want to extract the very laster number (15) in the function isAuthorized so i can unothorized users to no access pages to edit other’s password.

Thanks in advance

What does the signature of your editpass function look like? Unless you’ve done something weird with routing, you should be able to just use function editpass($id) and the 15 will be in the $id variable.

Here is my editpass function, it allows a user to change its password and username with a form.
I made i like the default edit function of the UsersController and as you can see i did let the $id = null
43342a6bd94cccd16d599af2f400c853

My apologies, I missed the part about isAuthorized. Take a look at $this->request->params['pass'].

I got it with
$this->request->params[‘pass’][0];
(i added [0] because it’s an array).
Thank you very much !

Here is my final isAutorized function :

public function isAuthorized($user){
   if($this->request->getParam('action') ==='editpass' && $this->request->getParam('pass')[0] === (string)$this->Auth->user('id'))
       return true;
   else
       return parent::isAuthorized($user);
}

Otherwise you can use php function parse_url and get last key of your array (it’s also good to check if it’s is_numeric or not)

$last_key = key(array_slice($array, -1, 1, TRUE));