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
Post a Comment