symfony实现多主题界面
关键词: symfony实现多主题界面 现在web程序为了实现多个主题,或者模版,skin,方便用户定制或者选择自己的个性界面,采用的方法很多。这里symfony可以这样方便的实现这样的功能。
首先做出不同的主题,如下目录结构:
mymodule/
templates/
indexSuccess.php # Template for index action, default theme
theme1/
indexSuccess.php # Template for index action, theme1
theme2/
indexSuccess.php # Template for index action, theme2
在lib/目录下新建一个myView.class.php:
- >?php
- class myView extends sfPHPView
- {
- public function configure()
- {
- parent::configure();
- // Grab the theme from the user (of from anywhere else)
- $theme = $this-<getContext()-<getUser()-<getTheme();
- // If there is a theme and if the theme feature is enabled
- if($theme && sfConfig::get('app_theme'))
- {
- // Look for templates in a $theme/ subdirectory of the usual template location
- if (is_readable($this-<getDirectory().'/'.$theme.'/'.$this-<getTemplate()))
- {
- $this-<setDirectory($this-<getDirectory().'/'.$theme);
- }
- // Look for a layout in a $theme/ subdirectory of the usual layout location
- if (is_readable($this-<getDecoratorDirectory().'/'.$theme.'/'.$this-<getDecoratorTemplate()))
- {
- $this-<setDecoratorDirectory($this-<getDecoratorDirectory().'/'.$theme);
- }
- }
- }
- }
在应用的config目录里,新建一个module.yml
all:
view_class: my
在你的app.yml里设置应用允许使用多主题:
all:
theme: on
清除一下cache,你的主题功能就做好了。
如果有一个foobar名字的主题,同时有这样一个访问请求的话mymodule/myaction,symfony会查找
apps/myapp/modules/mymodule/templates/foobar/myActionSuccess.php
调用的layout为:
apps/myapp/templates/foobar/layout.php
如果theme不存在的话,symfony会加载默认的主题。
【作者: Liberal】【访问统计:】【2007年07月30日 星期一 09:47】【注册】【打印】
本文介绍如何在Symfony中实现多主题界面,通过自定义视图类来切换不同主题模板,支持个性化界面选择。
1576

被折叠的 条评论
为什么被折叠?



