Codxplore.com

Latest news:

Sahih al-Bukhari (সহীহ বুখারী) is a free Hadith application for android. This application is advertisement free. Download now https://play.google.com/store/apps/details?id=com.akramhossin.bukharisharif

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 https://www.yiiframework.com/doc/api/2.0/yii-base-view#$context-detail

Tags : PHP, Yii2,

Views : 3017

Subscribe Us


Follow Us