Blog index.php Web application entry script file assets/ containing published resource files css/ containing CSS files images/ containing image files themes/ containing application themes protected/ containing protected application files yiic yiic command line script yiic.bat yiic command line script for Windows commands/ containing customized 'yiic' commands shell/ containing customized 'yiic shell' commands components/ containing reusable user components MainMenu.php the 'MainMenu' widget class Identity.php the 'Identity' class used for authentication views/ containing view files for widgets mainMenu.php the view file for 'MainMenu' widget config/ containing configuration files console.php the console application configuration main.php the Web application configuration controllers/ containing controller class files SiteController.php the default controller class extensions/ containing third-party extensions messages/ containing translated messages models/ containing model class files LoginForm.php the form model for 'login' action ContactForm.php the form model for 'contact' action runtime/ containing temporarily generated files views/ containing controller view and layout files layouts/ containing layout view files main.php the default layout for all views site/ containing view files for the 'site' controller contact.php the view for 'contact' action index.php the view for 'index' action login.php the view for 'login' action system/ containing system view files
go to down load FCK via http://www.yiiframework.com/extension/fckeditor-integration/files/fckeditor-integration-0.0.4.zip
put it to extensions目录 <?php $this->widget('application.extensions.fckeditor.FCKEditorWidget',array( "model"=>$pages, # Data-Model "attribute"=>'content', # Attribute in the Data-Model "height"=>'400px', "width"=>'100%', "toolbarSet"=>'Basic', # EXISTING(!) Toolbar (see: fckeditor.js) "fckeditor"=>Yii::app()->basePath."/../fckeditor/fckeditor.php", # Path to fckeditor.php "fckBasePath"=>Yii::app()->baseUrl."/fckeditor/", # Realtive Path to the Editor (from Web-Root) "config" => array("EditorAreaCSS"=>Yii::app()->baseUrl.'/css/index.css',), # Additional Parameter (Can't configure a Toolbar dynamicly) ) ); ?> public function actionCreate() { $model=new Post; if(isset($_POST['post'])) { $model->attributes=$_POST['post']; if($model=>save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('create',array('model'=>$model)); } public function actionUpdate() { $model=$this->loadModel(); if(isset($_POST['post'])) { $model->attributes=$_POST['post']; if($model=>save()) $this->redirect(array('view','id'=>$model->id)); } $this->render('update',array('model'=>$model)); } <div class='title'><?php echo CHtml::encode($data->title);?></div> <?php $this->beginWidget('CMarkdown',array('purifyOutput'=>true)); echo $data->content_short; $this->endWidget();?> </div> public function rules(){ return array( array('password','cmpPassword'), ); } public function cmpPasswd($attribute,$params) { if(!$this->hasErrors()) { if(!$this->re_passwd!=$this->password) { $this->addError('re_passwd','please confirm your repassword'); }else{ $this->salt=$this->generateSalt(); $this->password=$this->hashPassword($this->password,$this->salt); } } } <div class='row'> <?php echo CHtml::activeLabelEx($model,'re_passwd');?> <?php echo CHtml::activeTextField($model,'salt',array('size'=>60,'maxlength'=>128));?> <?php echo CHtml::error($model,'re_passwd');?> </div> public function actionAdmin() { $criteria=new CDbCriteria(array()); if(Yii::app()->user->name!='admin'){ $criteria->addSearchCondition('author_id',Yii::app( )->user->id); $dataProvider=new CActiveDataProvider('Post', array( 'sort'=>array( 'defaultOrder'=>'status, update_time DESC', ), 'criteria'=>$criteria, )); $this->render('admin',array( 'dataProvider'=>$dataProvider, )); } }
添加站点新闻 CREATE TABLE tbl_news ( id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, content TEXT NOT NULL, status INTEGER NOT NULL, create_time INTEGER, update_time INTEGER ) D: cd D:\AppServ\www\blog ..\yii\framework\yiic shell >> model news >> crud news 创建联动菜单 http://yiiframework.net/post/84/%E8%81%94%E5%8A%A8%E4%B8%8B%E6%8B%89%E8%8F%9C%E5%8D%95
Yii::app()->cache->set($id,$value,30);//30sec Yii::app()->cache->set($id,$value,30,new CFileCacheDependency('FileName'));//30sec $value=Yii::app()->cache->get($id); if($value===false){}$cache=Yii::app()->cache; $cache['var1']=$value1; $value2=$cache['var2'];
Fragment cache <?php if($this->beginCache($id,array('duration'=>3600)){?> ...content to be cached <?php $this->endCache();?>
<?php if($this->beginCache($id, array('dependency'=>array( 'class'=>'system.caching.dependencies.CDbCacheDependency', 'sql'=>'SELECT MAX(lastModified) FROM Post')))) { ?> ...content to be cached... <?php $this->endCache(); } ?>
Nested Caching <?php if($this->beginCache($id1)) {?> ...outer content to be cached... <?php if($this->beginCache($id2)) { ?> ...inner content to be cached... <?php $this->endCache(); } ?> ...outer content to be cached... <?php $this->endCache(); }?>
Yii::import('ext.xyz.XyzClass');
Using 3rd party libraries protected/vendors/Zend/Search/Lucene.php Yii::import('application.vendors.*'); require once('Zend/Search/Lucene.php');
Once the above set up is ready, we can use the Lucene class in a controller action, like the following:
Nice URl array( 'posts'=>'post/list', 'post/<id:nd+>'=>'post/read', 'post/<year:ndf4g>/<title>'=>'post/read', )
1.Calling $this->createUrl('post/list') generates /index.php/posts. The rst rule is applied. 2 Calling $this->createUrl('post/read',array('id'=>100)) generates /index.php/post/ 100. The second rule is applied. 3 Calling $this->createUrl('post/read',array('year'=>2008,'title'=>'a sample post')) generates /index.php/post/2008/a%20sample%20post. The third rule is applied. 4 Calling $this->createUrl('post/read') generates /index.php/post/read. None of the rules is applied.
how to use theme Yii::app()->theme->baseUrl.'/images/FileName.gif'
how to log Yii::log($message,$leavel,$category); Yii::trace($message,$category);
how to using cookie // retrieve the cookie with the specified name $cookie=Yii::app()->request->cookies[$name]; $value=$cookie->value; ...... // send a cookie $cookie=new CHttpCookie($name,$value); Yii::app()->request->cookies[$name]=$cookie;
$cs=Yii::app()->clientScript; $cs->scriptMap=array( 'jquery.js'=>'/js/all.js', 'jquery.ajaxqueue.js'=>'/js/all.js', 'jquery.metadata.js'=>'/js/all.js', ...... ); <head> <?php echo CGoogleApi::init(); ?> <?php echo CHtml::script( CGoogleApi::load('jquery','1.3.2') . "nn" . CGoogleApi::load('jquery.ajaxqueue.js') . "nn" . CGoogleApi::load('jquery.metadata.js') ); ?> ...... </head> $lucene=new Zend Search Lucene($pathOfIndex); $hits=$lucene->find(strtolower($keyword));