Home  >  Article  >  Backend Development  >  Yii框架获取当前controlle和action对应id的方法,yiicontrolle_PHP教程

Yii框架获取当前controlle和action对应id的方法,yiicontrolle_PHP教程

WBOY
WBOYOriginal
2016-07-13 10:12:18795browse

Yii框架获取当前controlle和action对应id的方法,yiicontrolle

本文实例讲述了Yii框架获取当前controlle和action对应id的方法。分享给大家供大家参考。具体方法如下:

在Yiii框架开发中,你可能会要获取当前controlle或action的id,其实很简单,一句代码就实现了,以下是分别在controlle(控制器)和View(视图)中获取当前id的代码。

在控制器里:

复制代码 代码如下:
$name = $this->getId();  // controller

$name = $action->id;  // action


在视图里:
复制代码 代码如下:
$name = Yii::app()->controller->id;  // controller

$name = $this->getAction()->getId(); // action

希望本文所述对大家基于yii框架的PHP程序设计有所帮助。

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/920981.htmlTechArticleYii框架获取当前controlle和action对应id的方法,yiicontrolle 本文实例讲述了Yii框架获取当前controlle和action对应id的方法。分享给大家供大家参考...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn