We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

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();
    }
}


15.6k

The latest version

Hi,

The initialize methode exists in Controller: https://docs.phalcon.io/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.phalcon.io/en/latest/controllers#initializing-controllers