Yaf_Controller_Abstract 类
(Yaf >=1.0.0)
简介
Yaf_Controller_Abstract 是 Yaf 系统的 MVC 体系的核心部分。MVC 是指 Model-View-Controller,是一个用于分离应用逻辑和表现逻辑的设计模式。
每个自定义 controller 都应当继承 Yaf_Controller_Abstract。
自定义 controller 中无法定义 __construct 方法。因此,Yaf_Controller_Abstract 提供了一个魔术方法 Yaf_Controller_Abstract::init()。
如果自定义 controller 里已经定义了 init() 方法,当实例化 controller 的时候,它将被调用。
Action 可能需要参数,当请求来到的时候,在路由中如果请求的参数有相同名称的变量(例如:Yaf_Request_Abstract::getParam()),Yaf 将把他们传递给 action 方法(参阅 Yaf_Action_Abstract::execute())。
注意:
这些参数是直接获取的,没有过滤,使用他们之前应该仔细处理。
类摘要
属性
- actions
-
也可以通过使用此属性和 Yaf_Action_Abstract 在一个单独的 PHP 脚本中定义 action 方法。
示例 #1 在单独的文件中定义 action
<?php
class IndexController extends Yaf_Controller_Abstract {
protected $actions = array(
/** now dummyAction is defined in a separate file */
"dummy" => "actions/Dummy_action.php",
);
/* action method may have arguments */
public function indexAction($name, $id) {
/* $name and $id are unsafe raw data */
assert($name == $this->getRequest()->getParam("name"));
assert($id == $this->_request->getParam("id"));
}
}
?>示例 #2 Dummy_action.php
<?php
class DummyAction extends Yaf_Action_Abstract {
/* an action class shall define this method as the entry point */
public function execute() {
}
}
?> - _module
-
模块名
- _name
-
控制器名
- _request
-
当前请求实例
- _response
-
当前响应对象
- _invoke_args
- _view
-
视图引擎
目录
- Yaf_Controller_Abstract::__construct — Yaf_Controller_Abstract 构造方法
- Yaf_Controller_Abstract::display — The display purpose
- Yaf_Controller_Abstract::forward — 转发到另一个动作
- Yaf_Controller_Abstract::getInvokeArg — The getInvokeArg purpose
- Yaf_Controller_Abstract::getInvokeArgs — The getInvokeArgs purpose
- Yaf_Controller_Abstract::getModuleName — 获取当前控制器所属的模块名
- Yaf_Controller_Abstract::getName — Get self name
- Yaf_Controller_Abstract::getRequest — 检索当前请求对象
- Yaf_Controller_Abstract::getResponse — 检索当前响应对象
- Yaf_Controller_Abstract::getView — 获取当前的视图引擎
- Yaf_Controller_Abstract::getViewpath — The getViewpath purpose
- Yaf_Controller_Abstract::init — 控制器初始化
- Yaf_Controller_Abstract::initView — The initView purpose
- Yaf_Controller_Abstract::redirect — 重定向到 URL
- Yaf_Controller_Abstract::render — 渲染视图模板
- Yaf_Controller_Abstract::setViewpath — The setViewpath purpose
用户贡献的备注
备份地址:http://www.lvesu.com/blog/php/class.yaf-controller-abstract.php