您好,欢迎访问一九零五行业门户网

yii ar 增删改查 操作测试记录,yiiar_PHP教程

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 操作...
其它类似信息

推荐信息