随笔分类 - Yii Framework

摘要: Yii Framework实现前后台frontend,backend分离的方法有几种,总结如下:1. 分开入口文件目录结构index.phpadmin.phpassets/...其它目录protected/ config/ main.php components/ controllers/ ...其它目录 admin/ config/ main.php components/ controllers/ ...其它目录网站正常的入口文件是index.php,我们加多一...阅读全文
posted @ 2013-05-04 23:51 DavidHHuan 阅读(451) | 评论 (0) 编辑
摘要: 1. 先到微信公众平台注册帐号http://mp.weixin.qq.com2. 下载demo微信公众平台提供了一个十分“朴素”的demo,说明如何调用消息接口的。代码真的很朴素,具体内容可到官网下载。3. 按照Yii的规则,做一个extension。这里命名为 weixin,目录结构如下:▾ extensions/ ▾ weixin/ Weixin.php*Weixin.php代码内容:<?php/** * WeixinCallback * * @package * @version $id$ * @copyright 1997-2005 The PHP Group * @...阅读全文
posted @ 2013-04-02 21:26 DavidHHuan 阅读(3722) | 评论 (1) 编辑
摘要: php版本davidhhuan@davidhhuan-ThinkPad-T410:~$ php -versionPHP 5.3.10-1ubuntu3.4 with Suhosin-Patch (cli) (built: Sep 12 2012 18:59:41) Copyright (c) 1997-2012 The PHP GroupZend Engine v2.3.0, Copyright (c) 1998-2012 Zend TechnologiesYii版本1.1.13Yii Framework使用spl_autoload_register实现类的自动加载,这个很大的方便我们不用每次阅读全文
posted @ 2013-02-06 01:02 DavidHHuan 阅读(12850) | 评论 (0) 编辑
摘要: I found a good plugin for vim, that isYii API manual for Vim, which you can checkthe api in vim!here is the website:https://github.com/vim-scripts/Yii-API-manual-for-VimBut that, why i write this article is that, when iCreatting custom version follows:git clone https://github.com/yiisoft/yii.git /me阅读全文
posted @ 2013-01-12 03:08 DavidHHuan 阅读(16962) | 评论 (0) 编辑
摘要: when i using$command = Yii::app()->db->createCommand(" SELECT * FROM vote v LEFT JOIN works w ON w.id = v.works_id LEFT JOIN activity a ON a.id = w.activ...阅读全文
posted @ 2012-12-28 15:36 DavidHHuan 阅读(12522) | 评论 (0) 编辑
摘要: When developing distributed applications with Yii, naturally, we will face that we have toshare the session in different machine. So here we will use memcache to do it.here is the example to store the session with memcache in Yii, in the main.php file: 'cache'=>array('class'=>&阅读全文
posted @ 2012-11-22 02:09 DavidHHuan 阅读(9769) | 评论 (1) 编辑
摘要: All the content of this article only happend in Yii Framework!As we know, with a form, we can both use post and get to send the data. But in Yii, when creating a form as below:<?phpechoCHtml::beginForm('user/index','get');?><?phpechoCHtml::label('User','user01阅读全文
posted @ 2012-10-15 10:10 DavidHHuan 阅读(378) | 评论 (0) 编辑
摘要: As we know, in Yii, we can set the error handler to display some useful message to the user.But, when i want to display different views in different modules, how to do it?Here is the way.In your module, here let say we have a admin module, there isAdminModule.php in it,then add the code as below:pub阅读全文
posted @ 2012-10-03 16:55 DavidHHuan 阅读(324) | 评论 (0) 编辑
摘要: From the code generated by the yiic, as we know, using these code can only get id and username from Yii::app()->user after logined:$identity=newUserIdentity($_POST['LoginForm']['username'],$_POST['LoginForm']['password']);Yii::app()->user->login($identity);bu阅读全文
posted @ 2012-09-07 14:01 DavidHHuan 阅读(218) | 评论 (0) 编辑
摘要: 再谈Yii Framework中的事件event,我写过的关于Yii事件event的另一篇文章[Yii Framework] Yii中事件和行为的区别和应用 http://www.cnblogs.com/davidhhuan/archive/2012/01/19/2326123.html假设有类MyComponent,它是继承于CComponent,通过查看 CComponent 的 __set() 方法,publicfunction__set($name,$value){$setter='set'.$name;if(method_exists($this,$setter))r阅读全文
posted @ 2012-07-23 16:28 DavidHHuan 阅读(360) | 评论 (0) 编辑
摘要: This article comes fromhttp://www.yiiframework.com/wiki/155/the-directory-structure-of-the-yii-project-siteOverall StructureTop-level DirectoriesApplication DirectoriesThe Common DirectoryApplication ConfigurationsPath AliasDeploymentLinksIn this article, we describe the directory structure used by 阅读全文
posted @ 2012-07-19 11:43 DavidHHuan 阅读(752) | 评论 (0) 编辑
摘要: 这里假设我们要建立 中文/英文 切换的站点1. 设置全局默认的语言文件添加代码:protected/config/main.php'language'=>'zh_cn',2. 控制器根据用户选择动态切换语言一般来说,我们所有的控制器都是继承于 protected/components/Controller.php 这个类。因此,我们可以在这个类里面进行语言的定义来影响当前的请求。publicfunctioninit(){if(isset($_GET['lang'])&&$_GET['lang']!="阅读全文
posted @ 2012-06-15 15:47 DavidHHuan 阅读(32367) | 评论 (3) 编辑
摘要: 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 阅读(163) | 评论 (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 阅读(1571) | 评论 (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 阅读(249) | 评论 (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 阅读(212) | 评论 (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 阅读(215) | 评论 (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 阅读(1054) | 评论 (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 阅读(965) | 评论 (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 阅读(787) | 评论 (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 阅读(164) | 评论 (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 阅读(405) | 评论 (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 阅读(381) | 评论 (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 阅读(427) | 评论 (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 阅读(477) | 评论 (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 阅读(183) | 评论 (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 阅读(312) | 评论 (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 阅读(160) | 评论 (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 阅读(209) | 评论 (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 阅读(174) | 评论 (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 阅读(346) | 评论 (0) 编辑
摘要: 下面语句就可以获取当前控制器的名称了!Yii::app()->controller->id阅读全文
posted @ 2010-04-21 11:56 DavidHHuan 阅读(487) | 评论 (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 阅读(401) | 评论 (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 阅读(562) | 评论 (0) 编辑
摘要: 要创建一个新的挂件(widget),我们主要是要继承两个方法:CWidget::init()和 CWidget::run(),CWidget::init 调用是发生在我们使用 $this->beginWidget 将挂件插入到一个view里面,CWidget::run 调用是发生在我们使用 $this->endWidget 这个方法的时候。 如果我们想捕捉和处理两者之间的方法核查办上显...阅读全文
posted @ 2010-04-21 11:55 DavidHHuan 阅读(248) | 评论 (0) 编辑
摘要: 比如要使用mySQL中的md5函数,Test::model()->findAll(new CDbExpression("md5(name) =1"));阅读全文
posted @ 2010-04-21 11:55 DavidHHuan 阅读(268) | 评论 (0) 编辑
摘要: 假设数据库的设置已经弄好了,里面的有一个User表建立User模型model User建立User的CRUD行为crud User创建 Modulemodule forum阅读全文
posted @ 2010-04-21 11:54 DavidHHuan 阅读(350) | 评论 (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 阅读(239) | 评论 (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 阅读(252) | 评论 (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 阅读(327) | 评论 (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 阅读(328) | 评论 (0) 编辑
摘要: public function filters(){ return array( ’postOnly + edit, create’, array( ’application.filters.PerformanceFilter - edit, create’, ’unit’=>’second’, ...阅读全文
posted @ 2010-04-21 11:52 DavidHHuan 阅读(267) | 评论 (0) 编辑
摘要: 创建[代码]调用[代码]阅读全文
posted @ 2010-04-21 11:52 DavidHHuan 阅读(674) | 评论 (10) 编辑
摘要: 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 阅读(588) | 评论 (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 阅读(421) | 评论 (0) 编辑
摘要: $this->widget('CMaskedTextField',array('mask'=>'99/99/9999'));阅读全文
posted @ 2010-04-21 11:51 DavidHHuan 阅读(267) | 评论 (0) 编辑
摘要: Ajax请求页面块的时候,是不希望加载layout的,这时候怎么向页面块传递参数呢?可以使用renderPartial()来代替render()阅读全文
posted @ 2010-04-21 11:51 DavidHHuan 阅读(376) | 评论 (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 阅读(164) | 评论 (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 阅读(180) | 评论 (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 阅读(325) | 评论 (0) 编辑
摘要: public function ValidatorName($attribute,$params) f ... G阅读全文
posted @ 2010-04-21 11:49 DavidHHuan 阅读(171) | 评论 (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 阅读(253) | 评论 (0) 编辑
摘要: $post->delete();进行以上操作的之后,AR实体是没有发生改变的,但是数据库里面的记录已经发生改变了阅读全文
posted @ 2010-04-21 11:48 DavidHHuan 阅读(166) | 评论 (0) 编辑
摘要: 用一个方法来代替使用CActiveRecord::scopes例如public function recently($limit=5){$this->getDbCriteria()->mergeWith(array(’order’=>’createTime DESC’,’limit’=>$limit,)...阅读全文
posted @ 2010-04-21 11:47 DavidHHuan 阅读(176) | 评论 (0) 编辑
摘要: 在数据查询的时候,出现下面的是什么意思?$posts=Post::model()->published()->recently()->findAll();这个是叫做named scope,每个命名范围被声明为一个可以被用来初始化CDbCriteria阵列实例。如要下面的例子class Post extends CActiveRecord{......public function...阅读全文
posted @ 2010-04-21 11:47 DavidHHuan 阅读(192) | 评论 (0) 编辑
摘要: MANY_MANY不能使用的属性:onBELONGS_TO不能使用的属性:limit Offset阅读全文
posted @ 2010-04-21 11:46 DavidHHuan 阅读(205) | 评论 (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 阅读(273) | 评论 (0) 编辑
摘要: public function defaultScope(){return array(’condition’=>"language=’".Yii::app()->language."’",);}这个方法对于每个实例的CRUD都是影响的。阅读全文
posted @ 2010-04-21 11:46 DavidHHuan 阅读(168) | 评论 (0) 编辑
摘要: Components的方法引入以及定义:在config.php文件里面’components’=>array(’xyz’=>array(’class’=>’ext.xyz.XyzClass’,’property1’=>’value1&rsquo...阅读全文
posted @ 2010-04-21 11:45 DavidHHuan 阅读(285) | 评论 (0) 编辑
摘要: 在helper的extension里面,所有的方法只能是静态方法,就好像是全局方法一样,它的类名只是作为它的命名空间阅读全文
posted @ 2010-04-21 11:45 DavidHHuan 阅读(199) | 评论 (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 阅读(319) | 评论 (0) 编辑
摘要: 创建application component继承IApplicationComponent接口,或者继承CApplicationComponent类,一定要覆盖IApplicationComponent::init()这个方法,因为component的实例化的时候要做一些准备工作的。创建behavior继承IBehavior接口,或者继承CBehavior类,如果是为CModel或者CActiv...阅读全文
posted @ 2010-04-21 11:43 DavidHHuan 阅读(331) | 评论 (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 阅读(377) | 评论 (0) 编辑