Yii Framework

摘要: Official Website:http://www.chive-project.com/Here is its feature.Rich User interfaceChive is web-based and takes advantage of the capabilities of modern web browsers. See thescreenshotsfor impressions.Latest technologiesBased on top of the current version of the Yii framework, Chive takes advantage阅读全文
posted @ 2012-02-25 22:01 DavidHHuan 阅读(33) | 评论 (0) 编辑
摘要: 个人觉得,在 Yii 里面,最难以明白的就是事件(Event)和行为(behavior)了。这不仅仅是因为它们的概念比较难明,关键是它们的应用场景比较难明,不知道什么时候应该使用事件和行为来开发。关于 Yii 的事件和行为的描述,可参考 http://www.yiiframework.com/doc/api/1.1/CComponent本文参考的文章:http://yiibook.yiiblogs.com/?p=584http://www.larryullman.com/2010/07/20/forcing-login-for-all-pages-in-yii/http://www.yiifr阅读全文
posted @ 2012-01-19 09:35 DavidHHuan 阅读(149) | 评论 (0) 编辑
摘要: 这是我见过对 Yii Framework 的 CComponent 写得比较好的文章,原文地址:http://www.yiiframework.com/forum/index.php?/topic/17072-ccomponent%E5%9F%BA%E7%A1%80%E7%B1%BB/CComponentCComponent类为YII框架的基于组件和事件驱动编程提供了基础,YII框架中的大部分类都将CComponent类作为基类。CComponent类为它的子类提供3个特性:1、成员变量扩展通过定义两个成员函数(getXXX/setXXX)来定义一个成员变量,比如:public functio阅读全文
posted @ 2012-01-17 23:32 DavidHHuan 阅读(60) | 评论 (0) 编辑
摘要: Here is an example of how to develop a widget (yes, widget is also an extension in Yii) in Yii.Let say you want to display something with widget in the page, of course you can place your widget in protected/componentswhen there are one or two classes inside. But when there is a lot of them,it is har阅读全文
posted @ 2012-01-09 10:37 DavidHHuan 阅读(34) | 评论 (0) 编辑
摘要: Here we will use CLinkPager for example.when using CLinkPager widget, we always follow this way: <?$this->widget(‘CLinkPager’,array('pages'=>$pages,'pageSize'=>15,))?>Here we set it to display 15 items per page. But if we have many action view page with CLinkPager, we 阅读全文
posted @ 2012-01-04 16:02 DavidHHuan 阅读(33) | 评论 (1) 编辑
摘要: That is just a simple example here:<?php/****Export&importsql**@authordavidhhuan*/classDLDatabaseHelper{/***Exportthesqltoafile**@authordavidhhuan*@parambool$withData:Whethertoexporttheinsert-dataatthesametime*@parambool$dropTable:Addtodropthetableornot*@paramstring$saveName:thesavedfilename*阅读全文
posted @ 2011-12-30 00:03 DavidHHuan 阅读(68) | 评论 (0) 编辑
摘要: When we using CGridView in Yii, we may want to a link as a column. So in common sense, we will use CLinkColumn to do that, as these code:<?php$this->widget('zii.widgets.grid.CGridView',array('dataProvider'=>$dataProvider,'columns'=>array(array('name'=>&阅读全文
posted @ 2011-05-19 11:14 DavidHHuan 阅读(163) | 评论 (0) 编辑
摘要: What is CSRF, please see the details here.http://en.wikipedia.org/wiki/Cross-site_request_forgeryIn Yii, how to start the CSRF authorization? It is very easy to do that.Just add this to main.php[代码]And then, do something else to send a request to the server, you have to provide the YII_CSRF_TOKEN ( 阅读全文
posted @ 2011-01-19 15:41 DavidHHuan 阅读(221) | 评论 (0) 编辑
摘要: In Yii, we can define an action class and ask the controller to instantiate it. And we always create ourselves actions class in rootPath/protected/extensions, and the view file we called in the actions class always are located in rootPath/protected/views/ControllerNAME or rootPath/themes/ThemeNAME/C阅读全文
posted @ 2011-01-10 17:11 DavidHHuan 阅读(58) | 评论 (0) 编辑
摘要: Let say we have three table as:[代码]From their structure we can know that product table and category table are MANY_MANY relation, category_product is the middle table, then how can we get the product records when we have a category.id?Set the modelsProduct:代码Code highlighting produced by Actipro Cod阅读全文
posted @ 2010-12-11 19:22 DavidHHuan 阅读(173) | 评论 (0) 编辑
摘要: Here i will take stay.com for example, because this website i think is a very beatiful and flexiable website.For example, under her home page, the urls of the citys are as: http://www.stay.com/london,...阅读全文
posted @ 2010-10-28 18:01 DavidHHuan 阅读(208) | 评论 (0) 编辑
摘要: When reading the code of Yii blog example, we can find that, the code of site/login, as below:[代码]The LoginForm is located in protected/models, it extends from CFormModel, in the views/site/login.php,...阅读全文
posted @ 2010-10-22 17:58 DavidHHuan 阅读(177) | 评论 (0) 编辑
摘要: Here is a step by step to show how to run command in the server with yii framework.1. Create the web application.[代码]2. Edit myapp/protected/config/console.php:[代码]3. Create myapp/protected/commands/D...阅读全文
posted @ 2010-10-20 14:32 DavidHHuan 阅读(105) | 评论 (0) 编辑
摘要: In fact that I am too poor to buy a server to run my website, but I want to run cron auto, so I use ajax to do it! :PIn the file of the layout, add the code as below:代码in the path /site/cron, you can ...阅读全文
posted @ 2010-09-22 23:04 DavidHHuan 阅读(66) | 评论 (0) 编辑
摘要: Maybe there is not a good introduction about how to embed css and images in a module in the forum (or cookbook) of Yii framework, but thanks to Qiang, who builds the great framework, that I found the ...阅读全文
posted @ 2010-09-22 12:58 DavidHHuan 阅读(130) | 评论 (1) 编辑
摘要: 1. Create a file named "StringHelper.php", and locate it in protected/components , and insert the code as below:代码2. Demo[代码]Have fun with Yii! :)阅读全文
posted @ 2010-08-23 23:26 DavidHHuan 阅读(60) | 评论 (0) 编辑
摘要: There may be another good way to create and get the thumb image in Yii, here is my method to do it.1. You have to install this extension, "phpthumb", please search this extension in this website. 2. C...阅读全文
posted @ 2010-08-23 22:30 DavidHHuan 阅读(85) | 评论 (0) 编辑
摘要: By default, we can put the static pages in protected/views/site/pages.For example, I put the static "about.php" in protected/views/site/pages.The way of Yii to get the current name when to use in menu...阅读全文
posted @ 2010-07-21 22:49 DavidHHuan 阅读(55) | 评论 (0) 编辑
摘要: Below we list the core components that are pre-declared byCWebApplication.assetManager: CAssetManager -manages the publishing of private asset files.authManager: CAuthManager - manages role-based acce...阅读全文
posted @ 2010-07-07 23:04 DavidHHuan 阅读(209) | 评论 (0) 编辑
摘要: <?php$this->beginWidget('zii.widgets.jui.CJuiDialog', array('id'=>'myJuiDialog','options'=>array('title'=>'Edit the user profile','autoOpen'=>false,'buttons'=>array('ok'=>"js:f...阅读全文
posted @ 2010-04-21 11:56 DavidHHuan 阅读(183) | 评论 (0) 编辑
摘要: 下面语句就可以获取当前控制器的名称了!Yii::app()->controller->id阅读全文
posted @ 2010-04-21 11:56 DavidHHuan 阅读(242) | 评论 (0) 编辑
摘要: 比如要使用mySQL中的md5函数,Test::model()->findAll(new CDbExpression("md5(name) =1"));阅读全文
posted @ 2010-04-21 11:55 DavidHHuan 阅读(151) | 评论 (0) 编辑
摘要: 要创建一个新的挂件(widget),我们主要是要继承两个方法:CWidget::init()和 CWidget::run(),CWidget::init 调用是发生在我们使用 $this->beginWidget 将挂件插入到一个view里面,CWidget::run 调用是发生在我们使用 $this->endWidget 这个方法的时候。 如果我们想捕捉和处理两者之间的方法核查办上显...阅读全文
posted @ 2010-04-21 11:55 DavidHHuan 阅读(102) | 评论 (0) 编辑
摘要: 第一,比如说,我们要使用 Zend framework的东西。我们把zend framework解压到 prtected/vendors里面,现在的文件夹为 protected/vendors/Zend/Search/Lucene.php第二,在controller文件的头部,插入下面代码。Yii::import(’application.vendors.*’);requi...阅读全文
posted @ 2010-04-21 11:55 DavidHHuan 阅读(201) | 评论 (0) 编辑
摘要: 创建应用,假设yii的核心文件夹framework是放在/media/MyDocuments/xampp/htdocs/myyiicd /media/MyDocuments/xampp/htdocs/myyiiphp framework/yiic.php webapp /media/MyDocuments/xampp/htdocs/myyii阅读全文
posted @ 2010-04-21 11:54 DavidHHuan 阅读(107) | 评论 (0) 编辑
摘要: 把/media/MyDocuments/xampp/htdocs/myyii下面的index.php复制到/media/MyDocuments/xampp/htdocs/myyii/protected下面,然后将下面的代码$yii=dirname(__FILE__).'/framework/yii.php';$config=dirname(__FILE__).'/protected/config/...阅读全文
posted @ 2010-04-21 11:54 DavidHHuan 阅读(117) | 评论 (0) 编辑
摘要: 假设数据库的设置已经弄好了,里面的有一个User表建立User模型model User建立User的CRUD行为crud User创建 Modulemodule forum阅读全文
posted @ 2010-04-21 11:54 DavidHHuan 阅读(196) | 评论 (0) 编辑
摘要: mysql:代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->'db'=>array('connectionString'=>'mysql:host=localhost;dbname=tsmp','username'=>'root','password'=>'1','charset'=>'utf8', 'tablePrefix'=>'tbl_',//'schemaCachingDuration'=>3600,//如果在main.php里面设置了c阅读全文
posted @ 2010-04-21 11:53 DavidHHuan 阅读(75) | 评论 (0) 编辑
摘要: <?php return array( 'class'=>'CUrlManager', 'urlFormat'=>'path', 'urlSuffix'=>'.html', 'showScriptName'=>false, 'caseSensitive'=>false,//it makes route case-insensitive. 'rules'=>...阅读全文
posted @ 2010-04-21 11:53 DavidHHuan 阅读(148) | 评论 (0) 编辑
摘要: main.php文件'modules' => array( 'admin' => require(dirname(__FILE__).DIRECTORY_SEPARATOR.'backend.php') )backend.php文件<?phpreturn array( //'sizePerPage' => 10, 'defaultController'=>'user'...阅读全文
posted @ 2010-04-21 11:52 DavidHHuan 阅读(250) | 评论 (0) 编辑
摘要: 创建[代码]调用[代码]阅读全文
posted @ 2010-04-21 11:52 DavidHHuan 阅读(285) | 评论 (10) 编辑
摘要: public function filters(){ return array( ’postOnly + edit, create’, array( ’application.filters.PerformanceFilter - edit, create’, ’unit’=>’second’, ...阅读全文
posted @ 2010-04-21 11:52 DavidHHuan 阅读(132) | 评论 (0) 编辑
摘要: Ajax请求页面块的时候,是不希望加载layout的,这时候怎么向页面块传递参数呢?可以使用renderPartial()来代替render()阅读全文
posted @ 2010-04-21 11:51 DavidHHuan 阅读(163) | 评论 (0) 编辑
摘要: $this->widget('CMaskedTextField',array('mask'=>'99/99/9999'));阅读全文
posted @ 2010-04-21 11:51 DavidHHuan 阅读(127) | 评论 (0) 编辑
摘要: class MyWidget extends CWidget{public function init(){// this method is called by CController::beginWidget()}public function run(){// this method is called by CController::endWidget()}}通常,widget的视图是是放...阅读全文
posted @ 2010-04-21 11:51 DavidHHuan 阅读(260) | 评论 (0) 编辑
摘要: 以on开关定义方法,如要clicked事件,public function onClicked($event){$this->raiseEvent('onClicked', $event);}调用的时候$component->onClicked=$callback;如果$callback是一个全局对象里面的方法,要用以下array($object, 'methodName')方法应该定...阅读全文
posted @ 2010-04-21 11:50 DavidHHuan 阅读(72) | 评论 (0) 编辑
摘要: system: Yii framework directoryapplication: application's base directorywebroot: the directory containing the entry script fileext: directory of extensions阅读全文
posted @ 2010-04-21 11:50 DavidHHuan 阅读(68) | 评论 (0) 编辑
摘要: public function ValidatorName($attribute,$params) f ... G阅读全文
posted @ 2010-04-21 11:49 DavidHHuan 阅读(39) | 评论 (0) 编辑
摘要: 例如,要存储timestamp的值是用MySQL now()函数,这时候可以这样,$post = new Post;$post->createTime=new CdbExpression('NOW()');//$post->createTime='NOW()';will not work because 'NOW()' will be treated as a string$post-...阅读全文
posted @ 2010-04-21 11:49 DavidHHuan 阅读(120) | 评论 (0) 编辑
摘要: $post->delete();进行以上操作的之后,AR实体是没有发生改变的,但是数据库里面的记录已经发生改变了阅读全文
posted @ 2010-04-21 11:48 DavidHHuan 阅读(46) | 评论 (0) 编辑
摘要: 直接在views里面使用$this->method(),如controller里面:Class PostController extends Ccontroller{Puvlic function actionList(){....}Public function getTitle(){return 'test title';}}views的list.php<?php echo $th...阅读全文
posted @ 2010-04-21 11:48 DavidHHuan 阅读(108) | 评论 (0) 编辑
摘要: 在数据查询的时候,出现下面的是什么意思?$posts=Post::model()->published()->recently()->findAll();这个是叫做named scope,每个命名范围被声明为一个可以被用来初始化CDbCriteria阵列实例。如要下面的例子class Post extends CActiveRecord{......public function...阅读全文
posted @ 2010-04-21 11:47 DavidHHuan 阅读(67) | 评论 (0) 编辑
摘要: 用一个方法来代替使用CActiveRecord::scopes例如public function recently($limit=5){$this->getDbCriteria()->mergeWith(array(’order’=>’createTime DESC’,’limit’=>$limit,)...阅读全文
posted @ 2010-04-21 11:47 DavidHHuan 阅读(60) | 评论 (0) 编辑
摘要: public function defaultScope(){return array(’condition’=>"language=’".Yii::app()->language."’",);}这个方法对于每个实例的CRUD都是影响的。阅读全文
posted @ 2010-04-21 11:46 DavidHHuan 阅读(49) | 评论 (0) 编辑
摘要: 在components文件夹下面建立一个文件AutoTimestampBehavior.php,里面的内容为<?phpclass AutoTimestampBehavior extends CActiveRecordBehavior {/*** The field that stores the creation time*/public $createTime = 'creatTime';...阅读全文
posted @ 2010-04-21 11:46 DavidHHuan 阅读(111) | 评论 (0) 编辑
摘要: MANY_MANY不能使用的属性:onBELONGS_TO不能使用的属性:limit Offset阅读全文
posted @ 2010-04-21 11:46 DavidHHuan 阅读(69) | 评论 (0) 编辑
摘要: Components的方法引入以及定义:在config.php文件里面’components’=>array(’xyz’=>array(’class’=>’ext.xyz.XyzClass’,’property1’=>’value1&rsquo...阅读全文
posted @ 2010-04-21 11:45 DavidHHuan 阅读(91) | 评论 (0) 编辑
摘要: 在helper的extension里面,所有的方法只能是静态方法,就好像是全局方法一样,它的类名只是作为它的命名空间阅读全文
posted @ 2010-04-21 11:45 DavidHHuan 阅读(64) | 评论 (0) 编辑
摘要: 假设使用的model名字为CommentModel里面Public function rules(){Return array(......Array('verifyCode', 'captcha', 'on'=>'insert', 'allowEmpty'=>!Yii::app()->user->isGuest || !extension_loaded('gd')),);...阅读全文
posted @ 2010-04-21 11:44 DavidHHuan 阅读(153) | 评论 (0) 编辑
摘要: 创建application component继承IApplicationComponent接口,或者继承CApplicationComponent类,一定要覆盖IApplicationComponent::init()这个方法,因为component的实例化的时候要做一些准备工作的。创建behavior继承IBehavior接口,或者继承CBehavior类,如果是为CModel或者CActiv...阅读全文
posted @ 2010-04-21 11:43 DavidHHuan 阅读(89) | 评论 (0) 编辑
摘要: 在main.php 里面配置return array(’theme’=>’basic’,......);要使用theme里面的资源的话,比如说images, js, css, 应该这样, Yii::app()->theme->baseUrl.”/images/FileName.gif”阅读全文
posted @ 2010-04-21 11:42 DavidHHuan 阅读(200) | 评论 (0) 编辑