[英]Lithium Views in Sub-directories
I am working on a website using the Lithium framework for PHP, and I need to have two sub-directories (ie. for admin and blog) with my controllers and views:我正在一个使用 Lithium 框架的 PHP 网站上工作,我需要有两个子目录(即用于管理员和博客)和我的控制器和视图:
-controllers
-admin
HomeController.php
...
-blog
HomeController.php
...
HomeController.php
...
-views
-admin
-home
index.html.php
...
...
-blog
-home
index.html.php
...
...
-layouts
default.html.php
admin.html.php
blog.html.php
So far, I have discovered the way to allow the use of sub-domains in the controller using the Dispach::config()
method:到目前为止,我已经发现了允许使用
Dispach::config()
方法在控制器中使用子域的方法:
Dispatcher::config(array('rules' => array(
'admin' => array('controller' => 'app\controllers\admin\{:controller}Controller'),
'blog' => array('controller' => 'app\controllers\blog\{:controller}Controller'),
)));
This works when you use the following routing:这在您使用以下路由时有效:
$options = array('continue' => true);
Router::connect('/admin', array(
'admin' => true,
'controller' => 'Home'
), $options);
Router::connect('/admin/{:args}', array(
'admin' => true
), $options);
Router::connect('/blog', array(
'blog' => true,
'controller' => 'Home'
), $options);
Router::connect('/blog/{:args}', array(
'blog' => true
), $options);
Now the problem I am having is that I can't figure out how to set it to automatically use the admin/blog
template and admin/blog
view folders.现在我遇到的问题是我不知道如何将它设置为自动使用
admin/blog
模板和admin/blog
视图文件夹。
You could override default templates paths thanks to Media.借助 Media,您可以覆盖默认模板路径。 The filter above sets different paths for admin requests (in config/bootstrap/media.php).
上面的过滤器为管理请求设置了不同的路径(在 config/bootstrap/media.php 中)。
Dispatcher::applyFilter('_callable', function($self, $params, $chain) {
$next = $chain->next($self, $params, $chain);
if ($params['request']->admin) {
Media::type('default', null, array(
'view' => 'lithium\template\View',
'paths' => array(
'layout' => '{:library}/views/layouts/{:layout}.{:type}.php',
'template' => '{:library}/views/admin/{:controller}/{:template}.{:type}.php'
)
));
}
return $next;
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.