php8.5
Home/ Manual/ reference / yaf/ The Yaf_Controller_Abstract class

The Yaf_Controller_Abstract class

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.

Intro

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.

Since Yaf_Controller_Abstract::__construct is called by Yaf with no arguments, Yaf_Controller_Abstract provides an alternative constructor-like hook: 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).

Note

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

Class synopsis

class Yaf_Controller_Abstract { }

Properties

actions

You can also define an action method in a separate PHP script by using this property and Yaf_Action_Abstract.

define action in a separate file

php
<?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"));
    }
}
?>

Dummy_action.php

php
<?php
class DummyAction extends Yaf_Action_Abstract {
    /* an action class shall define this method as the entry point */
    public function execute() {
    }
}
?>
_module

The name of the module the controller belongs to.

_name

The name of the controller.

_request

The current Yaf_Request_Abstract object.

_response

The current Yaf_Response_Abstract object.

_invoke_args

The invocation arguments passed to the action through Yaf_Controller_Abstract::forward, as an array keyed by argument name.

_view

The Yaf_View_Interface object used to render views.

Yaf-controller-abstract

Source: reference/yaf/yaf-controller-abstract.xml · from the official PHP manual (php/doc-en)