(Yaf >=1.0.0)
Yaf_Controller_Abstract 是Yaf的MVC體系的核心部分。 MVC是指Model-View-Controller, 是一個(gè)用于分離應用邏輯和表現邏輯的設計模式。
每個(gè)用戶(hù)自定義controller都應當繼承Yaf_Controller_Abstract。
你會(huì )發(fā)現在你自己的controller中無(wú)法定義__construct方法。因此,Yaf_Controller_Abstract 提供了一個(gè)魔術(shù)方法Yaf_Controller_Abstract::init()。
如果在你自己的controller里面已經(jīng)定義了一個(gè)init()方法,當你的controller被實(shí)例化的時(shí)候,它將被調用。
Action可能需要參數,當一個(gè)請求來(lái)到的時(shí)候,在路由中如果請求的參數有相同名稱(chēng)的變量(例如:Yaf_Request_Abstract::getParam()), Yaf將把他們傳遞給action方法(see Yaf_Action_Abstract::execute())。
$module
,$controller
= ?,$action
= ?,$paramters
= ?你也可以通過(guò)使用這個(gè)值和 Yaf_Action_Abstract 在一個(gè)單獨的PHP腳本中定義action函數。
示例 #1 在一個(gè)獨立的文件中定義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 indexAction($name, $id) {
assert($name == $this->getRequest()->getParam("name"));
assert($id == $this->_request->getParam("id"));
}
}
?>
示例 #2 Dummy_action.php
<?php
class DummyAction extends Yaf_Action_Abstract {
/* a action class shall define this method as the entry point */
public execute() {
}
}
?>
模塊名
當前的請求實(shí)例
視圖引擎