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

1.2.6: Fatal error: Call to a member function setVar() on a non-object in C:\...\IndexController.php

I'm trying to pass a variable to the view, but am getting the following error:

"Fatal error: Call to a member function setVar() on a non-object in C:...\IndexController.php"

class IndexController extends Phalcon\Mvc\View {
    public function indexAction() {
        $this->view->setVar('test', 'this is a test'); // This is the line it's complaining about
    }
}

Removing this line allows the page to load correctly. What is happening here?



40.8k
Accepted
answer
edited Oct '14

you extends View class for controller? Should be

class IndexController extends \Phalcon\Mvc\Controller

Oh duh! That's what it was. Thanks :)