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

Phalcon view controller is not controlling the view

I'm programming an admin web ui for a online system, I managed to mount a url to the view using,

$app->get(
        "/main/index",
        function () use ($app){
            //no echo here
            $app["view"]->render(
                "main","index"
            );
        }
   );

And my Main controller is like,

<?php

class MainController extends ControllerBase
{

    public function initialize()
    {
        $this->tag->setTitle('Home Page');

        $this->view->setTemplateAfter('nav');
    }

    public function indexAction()
    {

    }
}

My view structure is like,

views
--layouts
----index.volt
----nav.volt
--main
----index.volt
--index.volt

My problem is no matter how I change the MainController code, it doesn't affect anything on the rendered view main,index. So I wish to know what's wrong here?

All I wanted is just for all my pages, there can be a nav bar showing, the nav bar code should be in nav.volt file. However this is not working.



43.9k

Hi,

I think that you are trying to use MVC full stack framework in the context of a micro app.

If you want to use controllers with micro app have a look here: https://docs.phalcon.io/en/latest/reference/micro.html#using-controllers-as-handlers