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

Why the Rendering levels of MVC-View can't work properly?

I want to make the "Sign In/Up" page different from others, So, In my UsersController, most of the action like indexAction, profileAction will use the 3 view files:

  • view/index.volt
  • view/layouts/main.volt
  • view/users/index.volt or profile.volt

and the registerAction and loginAction will use ONLY 2 view files:

  • view/index.volt
  • view/users/register.volt or login.volt

That's I DON'T want this two actions to use the Controller Layout view/layouts/main.volt

thus, my code is like this:

class UsersController extends ControllerBase
{
    public function initialize()
    {
        parent::initialize();
        $this->view->setTemplateBefore("main");
    }

    public function indexAction()
    {
    }

    public function registerAction()
    {
        $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
        $form = new RegisterForm();
        ...
        $this->view->form = $form;
    }

    public function loginAction()
    {
        $this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_MAIN_LAYOUT);
        $form = new LoginForm();
        ...
        $this->view->form = $form;
    }

}

according to the code above, indexAction display properly(3 view files work well)

but the registerAction and loginAction still have the 3 view files! the view/layouts/main.volt still works!

How to correct it?

edited Nov '15

Cuz you just typed

View::LEVEL_MAIN_LAYOUT 

to use the main layout :D

Instead of

View::LEVEL_MAIN_LAYOUT 

use

View::LEVEL_ACTION_VIEW

maybe ?

To be honest i like to disable this auto generating views and handle it myself.



31.3k

View::LEVEL_ACTION_VIEW will use only view/users/register.volt, not the view/index.volt

Cuz you just typed

View::LEVEL_MAIN_LAYOUT 

to use the main layout :D

Instead of

View::LEVEL_MAIN_LAYOUT 

use

View::LEVEL_ACTION_VIEW

maybe ?

To be honest i like to disable this auto generating views and handle it myself.



31.3k

How to generate views manually?

Cuz you just typed

View::LEVEL_MAIN_LAYOUT 

to use the main layout :D

Instead of

View::LEVEL_MAIN_LAYOUT 

use

View::LEVEL_ACTION_VIEW

maybe ?

To be honest i like to disable this auto generating views and handle it myself.