Phalcon PhP - how to change the view dynamically

烈酒焚心 提交于 2019-12-04 02:00:34

问题


I'm working in a website where part of it I have the static html, so I created a layout and in it I'm inserting the static content using views. My problem is as this website has many pages I feel wrong creating an action for each url. So I implemented the controller below:

class PageController extends ControllerBase
{
    public function initialize(){
        $this->init();
        $this->view->setLayout( 'website' );
    }

    public function indexAction ($url=''){
        if($url == 'about')
            $this->view->pick('page/about');
    }
}

When I set the controller view to render $this->view->pick('page/about'); it doesn't insert the view in the template. It renders only the view.

Is there a way to render the view within the layout, and is there a better approach to what I'm doing?

Thanks for any help


回答1:


To load a template you should use

$this->view->setTemplateAfter('website');

instead of $this->view->setLayout( 'website' );

By using $this->view->pick('page/about'); you are overwriting the layout set by $this->view->setLayout( 'website' );, resulting in only seeing the page/about layout.



来源:https://stackoverflow.com/questions/39044087/phalcon-php-how-to-change-the-view-dynamically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!