Statement to create a new database
<?php class categorycontroller extends Controller{ Public function filters(){ return Array(' AccessControl ', ); } Public function accessrules(){ return Array(//More specific //Array ( //' Allow ', //' Actions ' =>array (' del ', ' Add '), //' users ' = = Array (' admin ') // ), Array(' Allow ',' actions '=Array(' index ',' del ',' Add ',' edit '),' users '=Array(' @ ') ),Array(' Deny ',' users '=Array(' * ') ), ); }/** * View column * * Public function actionindex(){ $categoryModel= Category::model ();$sql=the Select Cid,cname from{category}}";$categoryInfo=$categoryModel->findallbysql ($sql);$this->render (' index ',Array(' CategoryInfo '=$categoryInfo)); }/** * Add column * * Public function actionadd(){ $categoryModel=NewCategory ();if(isset($_post[' Category '])){$categoryModel->attributes =$_post[' Category '];if($categoryModel->save ()) {$this->redirect (Array(' index ')); } }//P ($_post); $this->render (' Add ',Array(' Categorymodel '=$categoryModel)); }/** * Edit column * * Public function actionedit($cid){ $categoryModel= Category::model ();$categoryInfo=$categoryModel->FINDBYPK ($cid);//P ($_post); if(isset($_post[' Category '])){$categoryInfo->attributes =$_post[' Category '];if($categoryInfo->save ()) {$this->redirect (Array(' index ')); } }$this->render (' edit ',Array(' Categorymodel '=$categoryInfo)); }/** * Delete Column * * Public function actiondel($cid){ $articleModel= Article::model ();$sql=the Select aid from{{article}} WHERE cid= $cid "; $articleInfo = $articleModel ->findbysql ( $sql ); if (Is_object ( $articleInfo )) {Yii::app ()->user->setflash ( ' Hasart ' , ' first); $this ->redirect (array ( )); }else {if (Category::model ()->deletebypk ( $cid )) { $this ->redirect (array ( ' index ' )); } } }}
Learning Summary of the Support network Yii Framework (10)--using the AR class to change the additions and deletions