Yii ar Additions and deletions to check operation test

Source: Internet
Author: User
Tags yii
Yii ar Additions and deletions to check operation Test record

Dear friends, I am yii small white don't laugh at me ao. Today to write a management module related to Yii ar curd operation, do update operation Tangled for a long time, this evening take a moment to learn, write down my test record

The code is as follows:

1      Public functionActionindex () {2 3         //Write Data4 //yii ar curd Insert5         $_post[' Users '] [' sex '] = 2;6         $_post[' Users '] [' username '] = ' Xiaohua ';7         $model=NewUsers;8         $model->attributes =$_post[' Users '];9         $rt=$model-save ();Ten  One         if($rt) { AYii::app ()->user->setflash (' Success ', ' Write succeeded '); -             $this->redirect (Array(' Index/test ')); -}Else { theYii::app ()->user->setflash (' Error ', ' failed '); -             $this->redirect (Array(' Index/test ')); -         } -  +      -         //Querying Data + //get one data by field A         $hh= Users::model ()Find ( at' Username=:name ',Array(': Name ' = ' FZB ')) -             ); -         Print_r($hh[' username ']); -  -         //get one data by ID -         $hh= Users::model ()->findbypk (1); in         Print_r($hh[' username ']); -  to         //Get All +         $hh= Users::model ()findAll (); -         Print_r($hh); the  *         //Modifying Data $ //Update OnePanax Notoginseng         $model=NewUsers; -         $count=$model->UPDATEBYPK (5,Array(' username ' = ' admin ', ' sex ' =>1)); the         if($count) { +Yii::app ()->user->setflash (' Success ', ' modified successfully '); A             $this->redirect (Array(' Index/test ')); the}Else { +Yii::app ()->user->setflash (' Error ', ' modification failed '); -             $this->redirect (Array(' Index/test ')); $         } $  -  -}

I hope the ladies have mercy.

I'm still a little white.

There are shortcomings in the hope that everyone points out, thank you!

  • Related Article

    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.