We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

undefined variable: dispatcher

<?php
class ErrorController extends ControllerBase
{   
    public function show404Action()
    {
        $this->$dispatcher->forward(array(
            'controller' => 'index',
            'action'     => 'index'
        ));
        return false;
    }

    public function show401Action()
    {
        //echo "show401"; die();
    }

    public function show500Action()
    {

    }

}

When show404 action is fired, that code gives me the following notice:

PHP Notice: Undefined variable: dispatcher

Should I define $this->dispatcher somehow?



98.9k
Accepted
answer

It should be:

$this->dispatcher->forward(array(

instead of:

$this->$dispatcher->forward(array(