//1,使用updateCounters()来更新计数器字段。
Book::model()->updateCounters(array('download_count'=>1),':id=id',array(':id'=>$id)); //2,使用sendFile()来下载文件。
$type = LFilter::checkString($_GET['t']);
$dataProvider = Book::model()->findByPk($id);
$content = $this->renderPartial('book',array(
'dataProvider' => $dataProvider,
'type' => $type,
),true,false);
Yii::app()->request->sendFile($dataProvider->name.'.'.$type,$content); //3,设计数据库时候如果create_time,update_time字段为int(10).在模型中使用行为插件。
public function behaviors()
{
return array(
'CTimestampBehavior' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'create_time',
'updateAttribute' => 'update_time',
)
); } //4,如果有些字段使用1,2,3之类的数字存储,在程序中使用时候含义不明确。可以model中加入如下函数.
private static $_items = array();
public static function loadItems($type,$code=null)
{
self::$_items = array(
'status' => array(
'1' => Yii::t('dh','开启'),
'2' => Yii::t('dh','关闭'),
),
'type' => array(
'1' => Yii::t('dh','产品'),
'2' => Yii::t('dh','文章'),
),
);
return $code ? self::$_items[$type][$code] : self::$_items[$type];
} //5,多语言使用Yii::t()函数。
public function attributeLabels()
{
return array(
'verifyCode'=>Yii::t('default','验证码'),
'name'=>Yii::t('default','名字'),
'email'=>Yii::t('default','邮箱'),
'subject'=>Yii::t('default','标题'),
'body'=>Yii::t('default','内容'),
'required'=>Yii::t('default','变量"{var}"没有定义',array('{var}'=>$var));
);
} //6,数据库表使用了前缀,则使用{{$tableName}}。
public function tableName()
{
return '{{product}}'; //7,Cookie的使用
//设置Cookie
$cookie=new CHttpCookie($name,$value);
$cookie=time()+60*60*24;
Yii::app()->request->cookies[$name]=$cookie;
//获取Cookie
$cookie=Yii::app()->request->cookies[$name];
$value=$cookie->value;
//删除Cookie
$cookie = Yii::app()->request->getCookies();
unset($cookie[$name]);
} //8,zii.widgets.jui.CJuiTabs的使用
<?php
$this->widget('zii.widgets.jui.CJuiTabs', array(
'tabs'=>array(
Yii::t('book','基本信息') => $this->renderPartial('_basic',array(
'model' => $model,
'form' => $form,
),true),
Yii::t('book','作品标签') => array('ajax'=> $this->createUrl('tag/boxList',array('tag'=>$model->tag))),
Yii::t('book','作品封面') => $this->renderPartial('_image',array(
'model'=>$model,
'form'=>$form,
),true),
Yii::t('book','作品公告') => $this->renderPartial('_notice',array(
'model'=>$model,
'form'=>$form,
),true),
),
// additional javascript options for the tabs plugin
'options'=>array(
'collapsible'=>false,
),
)); ?> //对于tabs而言,对于复杂内容的渲染结合使用renderPartial(); //9,zii.widgets.grid.CGridView的使用 <?php $this->widget('zii.widgets.grid.CGridView', array(
'id'=>'chapter-grid',
'dataProvider'=>$model->search(),
'filter'=>$model,
'columns'=>array(
'id',
//锚点<a href="http://blog.163.com/huv520@126/blog/"></a>
array(
'name'=>'name',
'type'=>'raw',
'value'=>'CHtml::link($data->name,"/book/$data->id")',
),
//图片
array(
'name'=>'image',
'type'=>'image',
'value'=>'LImages::getPath("book").$data->image',//图片相对路径
),
//下拉列表
array(
'name'=>'type',
'value'=>'Lookup::item("chapterType",$data->type)',
'filter'=>Lookup::items('chapterType'),
),
//内容截取
array(
'name'=>'content',
'type'=>'html',
'value'=>'mb_substr(htmlspecialchars_decode($data->content),0,100,"utf-8")',
),
//时间
array(
'name'=>'create_time',
'type'=>'datetime',
),
// 根据相关信息读数据库
array(
'name'=>'user_id',
'value'=>'User::model()->findbyPk($data->user_id)->username',
'filter'=>false,
),
array(
'class'=>'CButtonColumn',
),
),
)); ?> //10,findAll()的使用;
$params=array(
'select'=>'id,name,image',
'order'=>'total_point DESC',
'limit'=>5,
); $this->findAll($params);
find()使用同理,只是返回一条数据。
//11,readAll()返回数组结果集 $query = 'SELECT id,username FROM user';
$command = Yii::app()->db->createCommand($query);
return $command->query()->readAll();

YII 小模块功能的更多相关文章

  1. pandas模块实现小爬虫功能-转载

    pandas模块实现小爬虫功能 安装 pip3 install pandas 爬虫代码 import pandas as pd df = pd.read_html("http://www.a ...

  2. YII 小部件实现的注册表

    今天来进行用户注册功能yii集成了很多验证框架,framework/validators下面,这个文件夹的最后一个文件CValidator.php 是总的验证信息,根据请求参数决定需要那种验证 如:u ...

  3. 使用DeviceOne实现微信小程序功能

    微信小程序即将推出,还没推出就火的不行了.基于微信这个巨大平台,小程序必然能有巨大成功.不过它并不能完全取代App,该开发App还得开发.如果我们自己想实现一个基于自己的APP包含类似微信的小程序功能 ...

  4. python常用小模块使用汇总

    在写代码过程中常用到一些好用的小模块,现整理汇总一下: 1.获取当前的文件名和目录名,并添到系统环境变量中. file = os.path.abspath(__file__)             ...

  5. 基于Metronic的Bootstrap开发框架--工作流模块功能介绍(2)

    本篇继续<基于Metronic的Bootstrap开发框架--工作流模块功能介绍>,继续介绍基于Metronic的Bootstrap开发框架的工作模块功能,介绍工作流模块中相关业务表单的界 ...

  6. 基于Metronic的Bootstrap开发框架--工作流模块功能介绍

    在很早之前的随笔里面,已经介绍了WInform框架中工作流模块的功能,不过由于工作流模块中界面处理部分比较麻烦,一直没有在Bootstrap框架中进行集成,最近由于项目的关系,花了不少精力,把工作流模 ...

  7. Winform开发框架中的内容及文档管理模块功能介绍

    在开发项目的时候,我们有一些场景需要编辑一些HTML文档,作为内容发布系统的一部分,有时候也需要对一些文档如WORD文档进行编辑管理,这样需要我们对这些内容及文档进行合适的管理.本文主要介绍在WInf ...

  8. 怎样找到微信小程序功能呢?

    怎样找到微信小程序功能呢? 17年1月9号这个功能刚推出时,非常火,但我在微信中迟迟找不到微信小程序功能,微信明明更新到了最新版也没有:后来经过以下步骤才找到这个功能! 1.微信版本不能过低,这个一般 ...

  9. yii 修改模块使用的布局文件

    方法一:yii模块默认使用系统当前的主题布局文件,如果在主配置文件中配置了主题比如: 'theme'=>'mythm', 那么yii的模块就使用 protected/themes/mythm/v ...

随机推荐

  1. 【PHP】解决html网页乱码问题

    在自己制作一个网页时,时常会遇到网页乱码的问题. 其实导致网页乱码主要有几个原因,以下给出解决方法. 1.HTML的字符编码问题 该问题较常见,也是最明显和最容易解决的. 在网页<head> ...

  2. 网站开发常用jQuery插件总结(14)图片修剪插件Jcrop

    一.插件功能 用于对图片进行修剪.但是在使用Jcrop时,还需要配合服务器端开发语言(如asp.net,php等)使用. 二.官方地址 http://deepliquid.com/content/Jc ...

  3. onmouseleave与onmouseout区别

    1.onmouseleave.onmouseenter,鼠标进入到指定元素区域内触发事件,不支持冒泡,不包含子元素的区域. 2.onmouseout.onmouseover.鼠标进入指定元素触发事件, ...

  4. c#集合解析

    什么是集合(collection)? 提供了一种结构化组织任意对象的方式,从.NET 的角度看,所谓的集合可以定义为一种对象,这种对象实现一个或者多个System.Collections.IColle ...

  5. mongoDB单元测试

    http://blog.csdn.net/kiwi_coder/article/details/37873093 内存mongo https://github.com/flapdoodle-oss/d ...

  6. ubuntu远程登陆windows

    首先安装rdesktop : apt-get install rdesktop.p 程序安装完后,在终端命令行中输入:$ rdesktop -g 1024x768 -d 24 ip,就进入了windo ...

  7. 结缘PDO

    起因 一直没有注意看数据库相关知识 几个月之前,无意打开如下一段代码: 被人吐槽是N年前的写法.后来也是学习需要,单一mysql已经不合适了.于是上网搜了一下好方法,PDO迎面而来. 诱惑 上网浏览时 ...

  8. spirng MVC乱码过滤器

    <filter> <filter-name>characterEncodingFilter</filter-name> <filter-class>or ...

  9. hairline!ios实现边框0.5px

    在2014WWDC上,Ted O’Connor提出了“retina hairlines”的解决方案,即在ratina屏幕上可以显示0.5px宽度的边框.他的方案是这样的: 1 Standard bor ...

  10. Android 图片比较

    Android中图片比较大致的流程如下: 将Drawable对象转化成Bitmap对象.(实际比较的是Bitmap对象,假设为B1和B2) 将B1和B2中的像素取出,分别放在2个数组中.(实际存储的是 ...