gpt4 book ai didi

phalcon - 如何在多模块 Phalcon 应用程序中使用 "Main Layout" View ?

转载 作者:行者123 更新时间:2023-12-04 20:48:56 28 4
gpt4 key购买 nike

我正在为我的 PhalconPHP 应用程序使用“多模块”MVC 结构。

我想弄清楚的一个问题是如何将我的“主布局” View 配置为位于模块 View 文件夹之上。

换句话说,我想要一个主“主布局”( as described here )并且我希望我的所有模块在该主布局 View 中的“ Controller View ”级别输出它们的 View 。

默认情况下,主布局 View 似乎取自

[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 版(因为它已卡住,待发布)中完成。

在您的模块中,您注册您的 View

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

等等。

您还可以拥有一个对所有模块通用的主视图,但不能是两者的组合。
//Registering a shared view component
$di->set(
'view',
function() {
$view = new \Phalcon\Mvc\View();
$view->setViewsDir('../apps/views/');
return $view;
}
);

this example在 Github 上。

这很可能是 0.7 版本的 NFR。

关于phalcon - 如何在多模块 Phalcon 应用程序中使用 "Main Layout" View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12951048/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com