Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CakePHP get action name

In CakePHP, it is possible to get the called function string using the

$this->action

syntax. It returns the literal string of whatever is called, so if the URL is /do_this, it returns do_this, and if it's doThis it'll return doThis. Regardless of the called method's real name.

What I am looking for, on the other hand, is the called method's actual name, no matter the URL syntax.

Is there a way to find it out?

I'd preferably be able to do this in the beforeFilter method.

like image 550
arik Avatar asked Jul 07 '14 10:07

arik


1 Answers

You should use the request object.

CakePHP 3.3 and below

$this->request->params['action'];

Since 3.4

$this->request->getParam('action');

I think this should contain the real method name that was called. CakePHPs router resolves the string URL to a controller / action pair and other args, all of that ends up in the request object. Read the documentation and do debug($this->request); in your beforeFilter() to see what else is there.

like image 183
floriank Avatar answered Oct 13 '22 13:10

floriank