array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'tr', ), 'this' => array ( 0 => 'class.yaf-controller-abstract.php', 1 => 'Yaf_Controller_Abstract', ), 'up' => array ( 0 => 'book.yaf.php', 1 => 'Yaf', ), 'prev' => array ( 0 => 'yaf-config-simple.valid.php', 1 => 'Yaf_Config_Simple::valid', ), 'next' => array ( 0 => 'yaf-controller-abstract.construct.php', 1 => 'Yaf_Controller_Abstract::__construct', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/yaf/yaf-controller-abstract.xml', ), 'extra_header_links' => array ( 'rel' => 'alternate', 'href' => '/manual/en/feeds/class.yaf-controller-abstract.atom', 'type' => 'application/atom+xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(Yaf >=1.0.0)
Yaf_Controller_Abstract is the heart of Yaf's system. MVC stands for Model-View-Controller and is a design pattern targeted at separating application logic from display logic.
Every custom controller shall inherit Yaf_Controller_Abstract.
You will find that you can not define __construct function for your custom controller, thus, Yaf_Controller_Abstract provides a magic method: Yaf_Controller_Abstract::init().
If you have defined a init() method in your custom controller, it will be called as long as the controller was instantiated.
Action may have arguments, when a request coming, if there are the same name variable in the request parameters(see Yaf_Request_Abstract::getParam()) after routed, Yaf will pass them to the action method (see Yaf_Action_Abstract::execute()).
Bilginize:
These arguments are directly fetched without filtering, it should be carefully processed before use them.
You can also define an action method in a separate PHP script by using this property and Yaf_Action_Abstract.
Örnek 1 define action in a separate file
<?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"));
}
}
?>
Örnek 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
controller name
current request object
current response object
view engine object