php8.5
Home/ Manual/ yaf / yaf_controller_abstract/ Yaf_Controller_Abstract::__construct

Yaf_Controller_Abstract::__construct

PHP function Edit on GitHub ✎

(Yaf >=1.0.0)

Constructor of Yaf_Controller_Abstract

Description

Yaf_Controller_Abstract::__construct()

Yaf_Controller_Abstract::__construct is called by Yaf when a controller object is created during dispatching. It takes no arguments, and users should not call it directly. Since it is not intended to be overridden with custom logic, Yaf_Controller_Abstract::init is provided as the userland initialization hook instead.

Parameters Parameters

Return Values

No value is returned.

Examples

Yaf_Controller_Abstract::__construct example

php
<?php
class IndexController extends Yaf_Controller_Abstract
{
    // __construct() is called by Yaf_Dispatcher when the controller
    // is instantiated during dispatching, and should be neither
    // called manually nor overridden. Define init() instead:

    public function init() {
        // by the time init() runs, the dispatcher has already wired
        // up the controller: the request, response and view engine
        // are all available
        var_dump($this->getRequest() instanceof Yaf_Request_Abstract);
        var_dump($this->getResponse() instanceof Yaf_Response_Abstract);
        var_dump($this->getView() instanceof Yaf_View_Interface);
    }

    public function indexAction() {
        // ...
    }
}
?>

The above example will output something similar to:

output
bool(true)
bool(true)
bool(true)

See Also

  • Yaf_Controller_Abstract::init

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