在Yii中获取当前的控制器ID [英] Getting Current Controller ID in Yii

查看:112
本文介绍了在Yii中获取当前的控制器ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取处理当前动作的当前控制器名称. 但是在我的情况下我将在布局文件的main.php中寻找当前控制器.

I want to get the current controller name that handles the current action. but the in my case I will look for the current controller in my main.php in my layout files.

这是我的目录结构的一个小视图,可让您了解布局文件以及将代码用于搜索控制器名称的文件

this is my small view of my directory structure to give you an idea where is my layout files and the file where i will put my codes in searching of my controller name

  • /受保护的
  • /主题
    • /mylayout
      • /布局
        • main.php
        • column1.php
        • column2.php
  • /protected
  • /themes
    • /mylayout
      • /layouts
        • main.php
        • column1.php
        • column2.php
  • index.php

这可能吗?我正在尝试以下代码,但我无法获取当前的控制器名称...

Is this possible? im trying the following codes but i failed to get my current controller name...

echo Yii::app()->controller->getId;
echo Yii:app()->getController->id;
echo Yii:app()->controller->uniqueID;

谢谢

推荐答案

<?php echo $this->getUniqueId();?>

这将显示当前控制器

这篇关于在Yii中获取当前的控制器ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆