A summary of learning about the framework of the backing net Yii (10)--using the AR class to change and delete

Source: Internet
Author: User

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-&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.