heming是一个在Web应用程序里定制网页外观的系统方式。通过采用一个新的主题,网页应用程序的整体外观可以立即和戏剧性的改变。

在Yii,每个主题由一个目录代表,包含view文件,layout文件和相关的资源文件,如图片, CSS文件, JavaScript文件等。主题的名字就是他的目录名字。全部主题都放在在同一目录WebRoot/themes下 。在任何时候,只有一个主题可以被激活。

提示:默认的主题根目录WebRoot/themes可被配置成其他的。只需要配置themeManager应用部件的属性basePathbaseUrl为你所要的值。

要激活一个主题,设置Web应用程序的属性theme为你所要的名字。可以在application configuration中配置或者在执行过程中在控制器的动作里面修改。

注:主题名称是区分大小写的。如果您尝试启动一个不存在的主题, yii: :app()->theme将返回null 。

主题目录里面内容的组织方式和application base path目录下的组织方式一样。例如,所有的view文件必须位于views下 ,布局view文件在views/layouts下 ,和系统view文件在views/system下。例如,如果我们要替换PostControllercreate 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目录可能包含安全敏感数据,应当配置以防止被网络用户访问。

当我们调用renderrenderPartial显示视图,相应的view文件以及布局文件将在当前激活的主题里寻找。如果发现,这些文件将被render渲染。否则,就后退到viewPathlayoutPath 所指定的预设位置寻找。

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 主题的更多相关文章

  1. yii主题

    修改应用的配置文件(protected/config/main.php)中加入 return array( ’theme’=>’basic’, ); 所有的视图文件必须位于views下 ,布局视 ...

  2. YII 主题设置

    节日不同,站点显示不同主题.就是解决问题. 也制作多套视图. 不是必需为全部页面设置主题,假设没有.就依照正常视图显示 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5 ...

  3. Yii 2.x 多主题 - 多语言 配置

    语言:只要在原来模板的位置建立语言目录 多主题:要重新定义模板的根目录

  4. PhpStorm 8.x/9.x 快捷键设置/个性化设置,如何多项目共存?如何更换主题?

    1."自定义"常用快捷键(设置成跟Eclipse差不多) 按照路径:File -> Settings -> Appearance & Behavior -> ...

  5. yii模块下面的组件

    模块的定义就不写了,直接进入主题看目录和文件: application/modules/client/controllers/UserController.php <?php class Use ...

  6. yii开发一个web程序的基本流程

    1. 创建目录结构.在前面的章节Creating First Yii Application写的yiic工具可以帮助我们快速完成这步. 2. 配置 application.就是修改applicatio ...

  7. Yii的学习(1)--安装配置

    之前在sina博客写过Yii的文章,来到博客园之后,没再写过关于Yii的文章,正好端午假期没啥事,就结合以前的博客,Yii的官方文档,再加上最近的关于Yii的收获总结一下,写个系列~~ Yii是一个基 ...

  8. yii和wp做博客

    第一步,安装yii和wp: 第二步,创建protected/components/ExceptionHandler.php文件 <?php class ExceptionHandler { pu ...

  9. yii 多模板

    main.php: //替换所有模板 //加载文件名为first的模板 //       'theme'=>'theme1', 'components'=>array(           ...

随机推荐

  1. RPM制作

    http://blog.csdn.net/justlinux2010/article/details/9905425

  2. Spring AOP + AspectJ Annotation Example---reference

    In this tutorial, we show you how to integrate AspectJ annotation with Spring AOP framework. In simp ...

  3. Android(java)学习笔记201:网络图片浏览器的实现(ANR)

    1.我们在Android下,实现使用http协议进行网络通信,请求网络数据.这里是获取网络上的图片信息,让它可以显示在手机上: 但是我们这个手机连接网络是很费时间,如果我们在主线程(UI线程)中写这个 ...

  4. Block之变量作用域

    在使用block的过程中经常会调用不同类型.不同作用域的变量,如果对这些变量作用域的理解稍有偏差,就会出现问题.故此特意整理出block中会经常使用到的几种变量,如有补充,欢迎指出. 1. 局部变量 ...

  5. ASP.NET Webform或者ASP.NET MVC站点部署到IIS下,默认情况下.json文件是不能被访问的,如果请求访问.json文件,则会出现找不到文件的404错误提示

    解决方法 <system.webServer> <staticContent> <remove fileExtension=".woff" /> ...

  6. CSS3伪类nth-child结合transiton动画实现文字若影若现

    css3伪类nth-child结合transiton动画实现文字若影若现收先创建一个div盒子,然后包裹在div中的有10个span标签每个span标签填上内容一次为A,B,C,D,E,F,G,H,I ...

  7. iPhone中如何判断当前相机是否可用

    UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera; if (![UIImag ...

  8. maven mirror

    国内连接maven官方的仓库更新依赖库,网速一般很慢,收集一些国内快速的maven仓库镜像以备用. ====================国内OSChina提供的镜像,非常不错=========== ...

  9. mac 下maven的安装

    最近在学习mahout,这些安装相关软件的步骤先记下来,避免以后忘记. 1.首先在mac上查看本机的java版本,如果没有需要自己去安装: 我的电脑上安装的java是1.7.0_79 2.在http: ...

  10. Linux抓包工具tcpdump详解

    tcpdump是一个用于截取网络分组,并输出分组内容的工具,简单说就是数据包抓包工具.tcpdump凭借强大的功能和灵活的截取策略,使其成为Linux系统下用于网络分析和问题排查的首选工具. tcpd ...