php - Yii2 - How to grab id inside layout -


i needing know id of page being viewed within layout. actually, it's rendered within layout.

site.com/controller/view/id 

or

site.com/controller/id  <-- shorthand same above 

i need id number earlier, within layout.

there $this->context->action->id returns view. don't see why isn't possible yii this. if doesn't exist, should add :)

i don't want chop url, that's chincy hack, , chincy hacks break later down road 1 reason or another.

you can $_get['id'] or \yii::$app->request->get('id');.

if have logic depending on controller , item id being viewed consider place widget, make layout more readable

edit:

id parameter name, in layout can use 2 approaches noted above or if want use context can $this->context->actionparams['id']


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -