Home > Backend Development > PHP Tutorial > Yii框架获取当前controlle和action对应id的方法_PHP

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

WBOY
Release: 2016-05-31 18:15:55
Original
828 people have browsed it

本文实例讲述了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程序设计有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template