php 如何在 yii2 中获取当前控制器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27796371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 23:32:06 来源:igfitidea点击:
How can I get current controller in yii2
提问by rdanusha
I'm trying to get current page controller in yii2? How can I achieve this in Yii2?
我想在 yii2 中获取当前页面控制器?我怎样才能在 Yii2 中实现这一点?
In Yii 1.0
在 Yii 1.0
Yii::app()->controller->action->id
Yii2 ?
yii2 ?
回答by Ranidu
use this code
使用此代码
Yii::$app->controller->id
回答by Kalpesh Desai
this may help...:)
这可能会有所帮助...:)
<?php echo Yii::$app->controller->id; //current controller id ?>
<?php echo Yii::$app->controller->action->id; //current controller action id ?>
回答by German Khokhlov
From view and layout files, you may use
从视图和布局文件,您可以使用
<?= $this->context->id //controller id ?>
<?= $this->context->action->id //action id ?>