1

I'm completely confused on how Phalcon PHP renders its views. I want to create a new page called "manager".

From my understanding by creating a controller I can link it to a view. I create a controller called ManagerController.php and then added a view in views/manager/index.volt.

I added a bit of text the volt file to check if it works. When I go to /manager/ nothing shows up.

Am I doing this correct or do I have to assign a view somewhere?

class ManagerController extends ControllerBase
{
    public function initialize()
    {
        $this->tag->setTitle('Files/My Files');
        parent::initialize();
    }
}
GNov
  • 105
  • 1
  • 13
  • Can we see the code of your controller, edited into your question? – halfer Jan 18 '15 at 14:58
  • Ive added it to the top – GNov Jan 18 '15 at 15:02
  • In most frameworks, you need to perform a "render" operation, specifying the view file. Is this the case with Phalcon, maybe? – halfer Jan 18 '15 at 15:06
  • I really dont know, if someone could guide me on how to create a view that would be great. – GNov Jan 18 '15 at 15:12
  • Worth a look at http://stackoverflow.com/questions/18486217/how-to-render-code-in-phalcon-view (though I think this is setting raw content, not using a view file). – halfer Jan 18 '15 at 15:13
  • 1
    Ah, it looks like [view files are rendered automatically](http://docs.phalconphp.com/en/latest/reference/views.html). OK, any errors in your logs? Debugging time! Also, do you need an `*Action` method in this controller? – halfer Jan 18 '15 at 15:15
  • I tried this but its not working. – GNov Jan 18 '15 at 15:17
  • I looked at that but it did not work. I did however find the problem in my code. – GNov Jan 18 '15 at 15:24

1 Answers1

2

The initialize function on a controller is an event ran after constructing the controller

In order to display view for that controller it is necessary to at least setup an index action

In your you are interested in rendering a route of /manager/ , this will correspond to indexAction

class ManagerController extends ControllerBase
{
    public function initialize()
    {
        $this->tag->setTitle('Files/My Files');
        parent::initialize();
    }
    public function indexAction()
    {
        // This will now render the view file located inside of
        // /views/manager/index.volt

        // It is recommended to follow the automatic rendering scheme
        // but in case you wanted to render a different view, you can use:
        $this->view->pick('manager/index');
        // http://docs.phalconphp.com/en/latest/reference/views.html#picking-views
    }

    // If however, you are looking to render the route /manager/new/
    // you will create a corresponding action on the controller with RouteNameAction:
    public function newAction()
    {
        //Renders the route /manager/new
        //Automatically picks the view /views/manager/new.volt
    }
}
David Duncan
  • 1,858
  • 17
  • 21