如何使用“主布局"多模块Phalcon应用程序中的视图? [英] How do I use "Main Layout" views in a multi module Phalcon application?

查看:72
本文介绍了如何使用“主布局"多模块Phalcon应用程序中的视图?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的PhalconPHP应用程序使用的是多模块" MVC结构.

I am using a "multi module" MVC structure for my PhalconPHP application.

我要解决的一个问题是如何将主布局"视图配置为在模块视图文件夹的上方.

One issue I am trying to figure out is how I can configure my "Main Layout" view to be above the module view folders.

换句话说,我想要一个主版主要版式"( (如此处所述),我希望所有模块在该主布局视图中的控制器视图"级别输出其视图.

In other words I want one master "Main Layout" (as described here) and I want all my modules to output their views at "Controller View" level within that main layout view.

默认情况下,显示的是主布局"视图,

At default it appears the Main Layout view is being taken from

[app]
 [module1]
    [controllers]
    [models]
    [views]
        (main layout is coming from here)
 [module2]
    [controllers]
    [models]
    [views]
        (main layout is coming from here)
 [views]
    (master main layout should come from here?)

我希望这是有道理的!

推荐答案

在此版本(稳定的0.5.0版)或下一个0.6.0(因为它已冻结,正等待发行)中,您无法找到所需的内容

What you are looking for cannot be done at this version (0.5.0 stable) or the next one 0.6.0 (since it is frozen, pending release).

在您的模块中注册您的视图

In your module you register your views

// /module1/Module.php

// Registering the view component
$di->set(
    'view', 
    function () {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../apps/module1/views/');
        return $view;
    }
);

// /module2/Module.php

// Registering the view component
$di->set(
    'view', 
    function () {
        $view = new \Phalcon\Mvc\View();
        $view->setViewsDir('../apps/module2/views/');
        return $view;
    }
);

以此类推.

您还可以拥有一个主视图,该视图对于所有模块都是通用的,但不能是两者的组合.

You can also have a master view that will be common for all modules, but not a combination of the two.

//Registering a shared view component
$di->set(
    'view', 
    function() {
    $view = new \Phalcon\Mvc\View();
    $view->setViewsDir('../apps/views/');
    return $view;
    }
);

请参阅Github上的此示例.

See this example on Github.

这很可能是0.7版本的NFR.

This could very well be a NFR for the 0.7 version.

这篇关于如何使用“主布局"多模块Phalcon应用程序中的视图?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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