How to build a blog using Yii1.1
Aim To familiarize the framework of Yii 1.1. How The steps can be found here The source code is stored at github repo Docker container for Nginx and PHP=FPM webserver, link Steps to note Download the Yii 1.1 source code at here Unpack the compressed file and move to dockerfolder/app tar -xvzf yii-1.1.22.bf1d26.tar.gz Rename the folder name to yii-1.1.22 Go to the framework folder to create a skeleton application by ./yiic webapp ../blog-yii1.1 Establish DB connection in /protected/config/database.php return array( 'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/blog.db', ); Allowing Gii for scafolding /protected/config/main.php 'import'=>array( 'application.models.*', 'application.components.*', ), 'modules'=>array( 'gii'=>array( 'class'=>'system.gii.GiiModule', 'password'=>'Password', 'ipFilters' = False, ), ), How to customize the rules method in /protected/models/Post.php public function normalizeTags($attribute,$params) { $this->tags=Tag::array2string(array_unique(Tag::string2array($this->tags))); } public function rules() { return array( array('title, content, status', 'required'), array('title', 'length', 'max'=>128), array('status', 'in', 'range'=>array(1,2,3)), array('tags', 'match', 'pattern'=>'/^[\w\s,]+$/', 'message'=>'Tags can only contain word characters.'), array('tags', 'normalizeTags'), array('title, status', 'safe', 'on'=>'search'), ); } How to customize the rules method in /protected/models/Tag.php public static function string2array($tags) { return preg_split('/\s*,\s*/',trim($tags),-1,PREG_SPLIT_NO_EMPTY); } public static function array2string($tags) { return implode(', ',$tags); } How to customize the relations method in protected/models/Post.php public function relations() { // NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array( 'author' => array(self::BELONGS_TO, 'User', 'author_id'), 'comments' => array(self::HAS_MANY, 'Comment', 'post_id', 'condition'=>'comments.status='.Comment::STATUS_APPROVED, 'order'=>'comments.create_time DESC'), 'commentCount' => array(self::STAT, 'Comment', 'post_id', 'condition'=>'status='.Comment::STATUS_APPROVED), ); } How to customize the relations method in protected/models/Comment.php class Comment extends CActiveRecord { const STATUS_PENDING=1; const STATUS_APPROVED=2; const STATUS_ARCHIVED=3 ...... How to create portlets for User Menu, Tag Cloud and Recent Comments 11.1 UserMenu portlet 11.2 TagCloud ...