Phalcon PhP-如何动态更改视图 [英] Phalcon PhP - how to change the view dynamically

查看:71
本文介绍了Phalcon PhP-如何动态更改视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在一个网站上工作,该网站的一部分包含静态html,因此我创建了一个布局,并在其中使用视图插入了静态内容.我的问题是,由于该网站有很多页面,因此我为每个网址创建操作都感觉不对.所以我在下面实现了控制器:

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');
    }
}

当我设置控制器视图以渲染$ 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?

感谢您的帮助

推荐答案

要加载模板,您应该使用

To load a template you should use

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

而不是$this->view->setLayout( 'website' );

使用$this->view->pick('page/about');覆盖了$this->view->setLayout( 'website' );设置的布局,导致仅看到page/about布局.

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.

这篇关于Phalcon PhP-如何动态更改视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆