LoginSignup
2
2

More than 5 years have passed since last update.

cakePHPでactionの引数を取得する方法

Last updated at Posted at 2015-04-19

validatesで独自の関数を使用する場合。
独自の関数の中でactionの引数を取得する方法

例えばURLが
http://duoprac/Questions/enBasic/2
の時 

Questionsがcontroller
enBasicがaction

となっている。独自の関数内でactionの引数を取得するには

getParamOfAction.php
var_dump(Router::parse(Router::url())['pass'][0]);

==>
string '2' (length=1)

test.php
var_dump(Router::parse(Router::url()));

==>
array (size=5)
'controller' => string 'Questions' (length=9)
'action' => string 'enBasic' (length=7)
'named' =>
array (size=0)
empty
'pass' =>
array (size=1)
0 => string '2' (length=1)
'plugin' => null

参考

Routerクラスの使い方 (CakePHP)

2
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2