Hello, i extend all my controllers from this one:
abstract class Controller extends Phalcon\Mvc\Controller
{
/**
* Disables layout if request is made via ajax
* @return void
*/
public function initialize()
{
if ($this->request->isAjax()) {
$this->view->setRenderLevel(Phalcon\Mvc\View::LEVEL_ACTION_VIEW);
}
}
}
So, all my actions render layout by default, but if it is ajax request - they do not. It's fine. But i have one controller, where all views are the same (data is very different, but views are really same). I want to use only one template instead of many same files. But, when in my controller i try to pick different view, it does not render a layout. Even if it is not ajax request. I even dropped my initialize() funtion to check. It just renders view without layout:
// Controller::initialize() or Controller::action() context, same result
$this->view->pick('index/index'); // always use index/index.phtml for all actions
Could you please advice the correct way to change view (if it is possible - for all actions in initialize() method in controller in one place), but to make layout appear when controller is handling non-ajax requests?
P.S. Methods names of View component are not self-explaining. Perhaps it is possible to make a little bit more self-explaining names in v 2.0?
E.g. setMainView() would be much more understandable with name setDefaultView(), pick() to setView() etc... It's unbeliveable hard to understand what methods are doing.. But the good framework should provide method names according to users' logical expectations...