yii ar 增刪改查 操作測試記錄,yiiar_PHP教程

來源:互聯網
上載者:User

yii ar 增刪改查 操作測試記錄,yiiar


親們, 我是yii小白 不要笑話我奧。今天白天寫一個管理模組涉及到 yii ar 下的 curd 操作,做 update 操作時糾結了好久,今天晚上花點時間學習, 下面寫下我的測試記錄

代碼如下:

 1     public function actionIndex(){ 2  3         // 寫入資料 4         //yii  ar  curd  之   insert 5         $_POST['Users']['sex'] = 2; 6         $_POST['Users']['username'] = 'xiaohua'; 7         $model = new Users; 8         $model->attributes = $_POST['Users']; 9         $rt = $model->save();10 11         if($rt) {12             Yii::app()->user->setFlash('success','寫入成功了');13             $this->redirect(array('index/test'));14         } else {15             Yii::app()->user->setFlash('error','失敗了');16             $this->redirect(array('index/test'));17         }18 19     20         // 查詢資料21         //get one data by field22         $hh = Users::model()->find(23               'username=:name',array(':name'=>'fzb')24             );25         print_r($hh['username']);26 27         //get one data by id28         $hh = Users::model()->findByPk(1);29         print_r($hh['username']);30 31         //get all32         $hh = Users::model()->findAll();33         print_r($hh);34 35         //  修改資料  36         // update  one37         $model = new Users;38         $count = $model->updateByPk(5,array('username'=>'admin','sex'=>1));39         if($count) {40             Yii::app()->user->setFlash('success','修改成功了');41             $this->redirect(array('index/test'));42         } else {43             Yii::app()->user->setFlash('error','修改失敗了');44             $this->redirect(array('index/test'));45         }46 47 48     }

希望大嬸們嘴下留情

我還是小白呢

有不足之處希望大家指出,謝謝!

http://www.bkjia.com/PHPjc/942277.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/942277.htmlTechArticleyii ar 增刪改查 操作測試記錄,yiiar 親們, 我是yii小白 不要笑話我奧。今天白天寫一個管理模組涉及到 yii ar 下的 curd 操作,做 update 操作...

  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    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.