what phalcon class extends to execute initialize method

hello !

What phalcon class extends to execute initialize method first?

Class test extends \Phalcon\........ 
{
    public function initialize(){
}

Try \Phalcon\Mvc\User\Component



7.2k
edited Sep '14

via Phalcon\Dispatcher You can try

<?php

class TestController extends \Phalcon\Mvc\Controller
{

  //This action will be executed after instance created
  public function initialize()
  {
    echo __FUNCTION__, "\n";
  }

  public function onConstruct()
  {
    echo __FUNCTION__, "\n";
  }

  public function anyAction()
  {
    echo __FUNCTION__, "\n";
  }


}

$d = new TestController();
$d->anyAction();

Without Phalcon\Dispatcher function initialize it's never called, because it's an event fire.

Out is ;

onConstruct
anyAction
edited Sep '14

Other option is use INVO structure

<?php

    use Phalcon\Mvc\Controller;

    class ControllerBase extends Controller
    {
        protected function initialize()
        {
            $this->tag->prependTitle('Title | ');
        }
    }

Then your class

    Class test extends ControllerBase
    {
        public function initialize(){
            //something here 
        }
    }