setLayout(); -AND pick()

Why, when install: $this->view->pick('help/avatar'); AND this: $this->view->setLayout('bModal'); Layout show only: \views\layouts\help.phtml But must: \views\layouts\bModal.phtml ????


what's mean?

"pick" has a higher priority than "setLayout".

You can do this (attention - this is the magic ;) ): $this->view->pick(array('help/avatar')); $this->view->setLayout('bModal');


@Nikolay thank you @netstu my english bad ))

I had an issue with pick & layout. I tried to do:


In this way layout didn't rendered. When I found this post and found @Nikolay post, then I tried:


In this way layout rendered. Thanks @Nikolay

Maybe someone knows why with and without array pick method works differently?

edited Oct '14

String sets both the layout and action view (expected string format "layout/action-view"). Array sets the layout and the action view separately - the element at index 0 sets the action view, the element at index 1 sets the layout (optional). You can not use a string to set only the action view, not setting layout:


this is analogous to:

$this->view->pick(['invoice/add/1', 'invoice']);

Sets the action view without changing the layout:


Sorry my english ;)

Is it possible to change main layout with pick method?

---- Nikolay <[email protected]> wrote ----



Thanks for this information!

This should be documented. Knowing this, the current documentation of pick() is very incomplete and partly wrong. ( i'll try to contribute next Weekend )

another note: using

  1. changes views-dir to ./views/foo
  2. changes action-template to bar AND
  3. (to me, this is unintentional magic) changes the Controller-Layout to foo

So after using the above pick(), \Phalcon\MVC\View will render ./views/foo/bar.phtml into ./views/layouts/foo.phtml (... into ./views/index.phtml )

This is weird, i think.

IMHO: To make it more intuitive, there should be one method for each level (i.e.: setMainLayout('path/file'), setLayout('path/file'), setTemplate('path/file')) and/or one method for all (i.e.: ->pick('path/template','path/layout','path/mainlayout'))