The Yaf_Controller_Abstract class

(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()).


These arguments are directly fetched without filtering, it should be carefully processed before use them.

Sınıf Sözdizimi

abstract class Yaf_Controller_Abstract {
/* Özellikler */
public $actions;
protected $_module;
protected $_name;
protected $_request;
protected $_response;
protected $_invoke_args;
protected $_view;
/* Yöntemler */
final private __construct()
protected display(string $tpl, array $parameters = ?): bool
public forward(string $action, array $paramters = ?): bool
public getInvokeArg(string $name): void
public getName(): string
public init(): void
public initView(array $options = ?): void
public redirect(string $url): bool
protected render(string $tpl, array $parameters = ?): string
public setViewpath(string $view_directory): void



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

class IndexController extends Yaf_Controller_Abstract {
$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

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


add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top