简体   繁体   English

PHP-Lithium框架如何更改/切换默认布局

[英]PHP - Lithium framework How to change/switch default layout

In PHP Lithium, how to change default layout? 在PHP Lithium中,如何更改默认布局? I have two layouts for different views, and I want to switch them in different views, how can I make this happen? 我有两种用于不同视图的布局,我想在不同视图中切换它们,如何使这种情况发生?

Thanks. 谢谢。

You switch the layout in the controller. 您在控制器中切换布局。 So when you are done in the controller you call render this way. 因此,当您在控制器中完成操作时,您将以这种方式调用渲染。

return $this->render(array('layout' => 'someFancyLayout'));

You should also be able to do this in your controller. 您还应该能够在控制器中执行此操作。 I'm not sure but you might need to extend the Controller to use this way. 我不确定,但是您可能需要扩展Controller以使用这种方式。

 $this->_render['layout'] = 'someFancyLayout';

Please note that you can also set up custom media handlers. 请注意,您还可以设置自定义媒体处理程序。 This is for instance used when requestting GPX-files and in that case I do not which to use a layout. 例如,这在请求GPX文件时使用,在这种情况下,我不使用布局。

Media::type('gpx', 'application/text', array(
    'view' => 'lithium\template\View',
    'layout' => false,
    'template' => false
));

And you can also do it with a filter on the renderer call: 您还可以在renderer调用中使用过滤renderer来执行此操作:

Media::applyFilter('render', function ($self, $params, $chain) {
    $params['options']['layout'] = 'default';
    if (someCondition == isMet) {
        $params['options']['layout'] = 'anotherLayout';
    }
    return $chain->next($self, $params, $chain);
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM