YII 主题
heming是一个在Web应用程序里定制网页外观的系统方式。通过采用一个新的主题,网页应用程序的整体外观可以立即和戏剧性的改变。
在Yii,每个主题由一个目录代表,包含view文件,layout文件和相关的资源文件,如图片, CSS文件, JavaScript文件等。主题的名字就是他的目录名字。全部主题都放在在同一目录WebRoot/themes下 。在任何时候,只有一个主题可以被激活。
提示:默认的主题根目录
WebRoot/themes可被配置成其他的。只需要配置themeManager应用部件的属性basePath和baseUrl为你所要的值。
要激活一个主题,设置Web应用程序的属性theme为你所要的名字。可以在application configuration中配置或者在执行过程中在控制器的动作里面修改。
注:主题名称是区分大小写的。如果您尝试启动一个不存在的主题,
yii::app()->theme将返回null。
主题目录里面内容的组织方式和application base path目录下的组织方式一样。例如,所有的view文件必须位于views下 ,布局view文件在views/layouts下 ,和系统view文件在views/system下。例如,如果我们要替换PostController的create view文件为classic主题下,我们将保存新的view文件为WebRoot/themes/classic/views/post/create.php。
对于在module里面的控制器view文件,相应主题view文件将被放在views目录下。例如,如果上述的PostController是在一个命名为forum的模块里 ,我们应该保存create view 文件为WebRoot/themes/classic/views/forum/post/create.php 。如果 forum模块嵌套在另一个名为support模块里 ,那么view文件应为WebRoot/themes/classic/views/support/forum/post/create.php 。
注:由于
views目录可能包含安全敏感数据,应当配置以防止被网络用户访问。
当我们调用render或renderPartial显示视图,相应的view文件以及布局文件将在当前激活的主题里寻找。如果发现,这些文件将被render渲染。否则,就后退到viewPath和layoutPath 所指定的预设位置寻找。
baseurl属性,我们就可以为此图像文件生成如下url,
yii">提示:在一个主题的视图,我们经常需要链接其他主题资源文件。例如,我们可能要显示一个在主题下
images目录里的图像文件。使用当前激活主题的baseurl属性,我们就可以为此图像文件生成如下url,yii: :app()->theme->baseUrl . '/images/FileName.gif'
Below is an example of directory organization for an application with two themes basic and fancy.
WebRoot/
assets
protected/
.htaccess
components/
controllers/
models/
views/
layouts/
main.php
site/
index.php
themes/
basic/
views/
.htaccess
layouts/
main.php
site/
index.php
fancy/
views/
.htaccess
layouts/
main.php
site/
index.php
In the application configuration, if we configure
return array(
'theme'=>'basic',
......
);
then the basic theme will be in effect, which means the application's layout will use the one under the directorythemes/basic/views/layouts, and the site's index view will use the one underthemes/basic/views/site. In case a view file is not found in the theme, it will fall back to the one under theprotected/views directory.
1. Theming Widgets 主题挂件
Starting from version 1.1.5, views used by a widget can also be themed. In particular, when we callCWidget::render() to render a widget view, Yii will attempt to search under the theme folder as well as the widget view folder for the desired view file.
To theme the view xyz for a widget whose class name is Foo, we should first create a folder named Foo (same as the widget class name) under the currently active theme's view folder. If the widget class is namespaced (available in PHP 5.3.0 or above), such as \app\widgets\Foo, we should create a folder namedapp_widgets_Foo. That is, we replace the namespace separators with the underscore characters.
创建一个Foo挂件的theme view xyz,我们应该在theme's view文件夹下创建Foo文件夹。
We then create a view file named xyz.php under the newly created folder. To this end, we should have a filethemes/basic/views/Foo/xyz.php, which will be used by the widget to replace its original view, if the currently active theme is basic.
2. Customizing Widgets Globally
//this feature has been available since version 1.1.3.
When using a widget provided by third party or Yii, we often need to customize it for specific needs. For example, we may want to change the value of CLinkPager::maxButtonCount from 10 (default) to 5. We can accomplish this by passing the initial property values when calling CBaseController::widget to create a widget. However, it becomes troublesome to do so if we have to repeat the same customization in every place we useCLinkPager.
$this->widget('CLinkPager', array(
'pages'=>$pagination,
'maxButtonCount'=>5,
'cssFile'=>false,
));
Using the global widget customization feature, we only need to specify these initial values in a single place, i.e., the application configuration. This makes the customization of widgets more manageable.
To use the global widget customization feature, we need to configure the widgetFactory as follows:
return array(
'components'=>array(
'widgetFactory'=>array(
'widgets'=>array(
'CLinkPager'=>array(
'maxButtonCount'=>5,
'cssFile'=>false,
),
'CJuiDatePicker'=>array(
'language'=>'ru',
),
),
),
),
);
In the above, we specify the global widget customization for both CLinkPager and CJuiDatePicker widgets by configuring the CWidgetFactory::widgets property. Note that the global customization for each widget is represented as a key-value pair in the array, where the key refers to the wiget class name while the value specifies the initial property value array.
Now, whenever we create a CLinkPager widget in a view, the above property values will be assigned to the widget, and we only need to write the following code in the view to create the widget:
$this->widget('CLinkPager', array(
'pages'=>$pagination,
));
We can still override the initial property values when necessary. For example, if in some view we want to setmaxButtonCount to be 2, we can do the following:
$this->widget('CLinkPager', array(
'pages'=>$pagination,
'maxButtonCount'=>2,
));
这个对pageSize无效。
参考:http://www.yiiframework.com/forum/index.php/topic/11510-cgridview-how-to-set-default-page-size/
http://danaluther.blogspot.com/2012/02/leveraging-widgets-widget-factory-and.html
YII 主题的更多相关文章
- yii主题
修改应用的配置文件(protected/config/main.php)中加入 return array( ’theme’=>’basic’, ); 所有的视图文件必须位于views下 ,布局视 ...
- YII 主题设置
节日不同,站点显示不同主题.就是解决问题. 也制作多套视图. 不是必需为全部页面设置主题,假设没有.就依照正常视图显示 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5 ...
- Yii 2.x 多主题 - 多语言 配置
语言:只要在原来模板的位置建立语言目录 多主题:要重新定义模板的根目录
- PhpStorm 8.x/9.x 快捷键设置/个性化设置,如何多项目共存?如何更换主题?
1."自定义"常用快捷键(设置成跟Eclipse差不多) 按照路径:File -> Settings -> Appearance & Behavior -> ...
- yii模块下面的组件
模块的定义就不写了,直接进入主题看目录和文件: application/modules/client/controllers/UserController.php <?php class Use ...
- yii开发一个web程序的基本流程
1. 创建目录结构.在前面的章节Creating First Yii Application写的yiic工具可以帮助我们快速完成这步. 2. 配置 application.就是修改applicatio ...
- Yii的学习(1)--安装配置
之前在sina博客写过Yii的文章,来到博客园之后,没再写过关于Yii的文章,正好端午假期没啥事,就结合以前的博客,Yii的官方文档,再加上最近的关于Yii的收获总结一下,写个系列~~ Yii是一个基 ...
- yii和wp做博客
第一步,安装yii和wp: 第二步,创建protected/components/ExceptionHandler.php文件 <?php class ExceptionHandler { pu ...
- yii 多模板
main.php: //替换所有模板 //加载文件名为first的模板 // 'theme'=>'theme1', 'components'=>array( ...
随机推荐
- 设置textView或者label的行间距方法
一,效果图. 二,代码. RootViewController.m - (void)viewDidLoad { [super viewDidLoad]; // Do any additional se ...
- Java多线程之释放对象的锁
由于等待一个锁定线程只有在获得这把锁之后,才能恢复运行,所以让持有锁的线程在不需要锁的时候及时释放锁是很重要的.在以下情况下,持有锁的线程会释放锁: 1. 执行完同步代码块. 2. 在执行 ...
- struts2 convention-plugin实现零配置
零配置并不是没有配置,而是通过约定大于配置的方式,大量通过约定来调度页面的跳转而使得配置大大减少.使得Action等配置不必写在Struts.xml中. convention-plugin的约定 1. ...
- TCP/IP协议原理与应用笔记02:断点续传
1.断点续传简介: FTP(文件传输协议的简称)(File Transfer Protocol. FTP)客户端软件断点续传指的是在下载或上传时,将下载或上传任务(一个文件或一个压缩包)人 ...
- 关于css中伪类及伪元素的总结
css中的伪类和伪元素总是混淆,今天参考了很多资料,也查看了部分文档,现将伪类及伪元素总结如下: 一.由来: 伪类和伪元素的引入都是因为在文档树里有些信息无法被充分描述,比如CSS没有"段落 ...
- SQL Server DBA工作内容详解
在Microsoft SQL Server 2008系统中,数据库管理员(Database Administration,简称为DBA)是最重要的角色.DBA的工作目标就是确保Microsoft SQ ...
- 10.6 noip模拟试题
更正:第三组:不存在相同的字符|str|=26,26<=n<=100 60 /* 呵呵哒~这题 正解还在研究.... 因为没有题解只有个std还在看 不过乱搞一下可以70(数据好像有问题只 ...
- MySQL 5.6 解决InnoDB: Error: Table "mysql"."innodb_table_stats" not found.问题
在安装MySQL 5.6.30时,安装完成后,后台日志报如下警告信息:2016-05-27 12:25:27 7fabf86f7700 InnoDB: Error: Table "mysql ...
- [转]Windows中的命令行提示符里的Start命令执行路径包含空格时的问题
转自:http://www.x2009.net/articles/windows-command-line-prompt-start-path-space.html 当使用Windows 中的命令行提 ...
- hdoj1847(博弈论)
代码: #include<stdio.h>int main(){ int N; while(scanf("%d",&N)!=EOF) printf(N%3==0 ...