Latest news:

Sahih al-Bukhari (সহীহ বুখারী) is a free Hadith application for android. This application is advertisement free. Download now

Yii2 - Get Current Action ID in main.php

 Yii2 - Get Current Action ID in main.php

Yii2 web application project, sometimes we need to current controller ID, action ID.

Specially when we need role based access control, we need to check the controller ID as well as action ID.

Using Yii2 view context api we can get these data.

for example if we need controller ID we can use below code

$controller = $this->context->action->controller->id;

if we need action ID only we can use as follows

$method = $this->context->action->id;

To know more about Yii2 view context api, please refer this link$context-detail

Tags : PHP, Yii2,

Views : 2838

Subscribe Us

Follow Us