Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Call to undefined method Phalcon\Mvc\Controller::initialize() in.....

ControllerBase.php

<?php

namespace Baby\Home\Controllers;

use Phalcon\Mvc\Controller;

class ControllerBase extends Controller
{

    public function initialize() {
        parent::initialize();
    }
}


10.6k

The latest version

Hi,

The initialize methode exists in Controller: http://docs.phalconphp.com/en/latest/reference/controllers.html#initializing-controllers

This works well for me:

  • BaseController.php
<?php

use \Phalcon\Tag;

class BaseController extends \Phalcon\Mvc\Controller
{
    public function initialize()
    {

        $this->tag->prependTitle('Test | ');
    }
}
  • IndexController.php
<?php

use Models,
    \Phalcon\Tag;

class IndexController extends BaseController
{

    public function initialize()
    {
        $this->tag->setTitle('Home');
        parent::initialize();
    }

    public function indexAction()
    {
        // ...
    }
}
edited Jan '18

As user screenas notes above, initialize is indeed part of the \Phalcon\Mvc\Controller. The official phalcon documentation states this as well:

The initialize() method is only called if the beforeExecuteRoute event is executed with success. This avoid that application logic in the initializer cannot be executed without authorization.

https://docs.phalconphp.com/en/latest/controllers#initializing-controllers