您现在的位置是:网站首页> 编程资料编程资料

yii2.0框架多模型操作示例【添加/修改/删除】_php实例_

2023-05-25 373人已围观

简介 yii2.0框架多模型操作示例【添加/修改/删除】_php实例_

本文实例讲述了yii2.0框架多模型操作。分享给大家供大家参考,具体如下:

控制器:

where(['id' => $id])->one(); if (!$user) { throw new NotAcceptableHttpException('没有找到用户信息'); } $league = shopLeagueInfo::findOne($user->league_id); if (!$league) { throw new NotAcceptableHttpException('没有找到加盟商信息'); } //model设置 $user->scenario = 'update'; $league->scenario = 'update'; if ($user->load(\Yii::$app->request->post()) && $league->load(\Yii::$app->request->post())) { $isValid = $user->validate(); $isValid = $league->validate() && $isValid; if ($isValid) { $user->save(false); $league->save(false); return $this->redirect(['user/save','id' => $id]); } } return $this->render('save',['user' => $user,'league' => $league]); } } 

model模型:

 ['user_phone'],//修改操作,值为表字段 ]; } } 

其他表同上。

views视图

 'save-form', 'options' => ['class' => 'form-horizontal'], ]) ?>field($user,'user_real_name')->input('user_real_name') ?>field($league,'user_phone')->input('user_phone') ?>

更多关于Yii相关内容感兴趣的读者可查看本站专题:《Yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

-六神源码网