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

Weird behaviour when picking view

I was using the $this->view->pick method in some action inside my controller and everything was working as expected. The main layout was working properly setting in the initialize method of my controller.

    public function initialize()
    {
        $this->view->setTemplateAfter('main');
        Tag::setTitle('Consultas');
        parent::initialize();
    }

But then I created my own menu component which renders an specific view like this:

    public function getSideMenu()
    {
        /** SOME CODE **/

        return $this->view->getRender('shared', 'side-menu', ['menu' => $menu], function ($view){
            $view->setRenderLevel(View::LEVEL_ACTION_VIEW);
        });
    }

As you can see I changed the render level inside the anonymous function, I suppose that shouldn't affect my existing controllers but it does. Now the pick method skips the main.volt inside my views/layouts folder. Hierachical rendering works fine so most of my controllers aren't affected but the one using the pick view doesn't work fine.

Explicitly setting the render level isn't working:

    public function estatusEvaluatorioAction()
    {
            /** SOME OTHER CODE **/
        $this->view->evaluados = $evaluados;
        $this->view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);
        $this->view->pick("consulta/estatus-resultado");
    }

The only workarounds I've found are not using $this->view->getRender() method in the component or simply not picking the view (using the hierarchical rendering).

Do you know if this is some kind of bug or am I missing something?



43.9k

Hi,

what happens if you comment

//$this->view->setRenderLevel(View::LEVEL_MAIN_LAYOUT);

@le51 it works exactly as if the line wasn't commented. Still getting same werid behaviour.