【发布时间】:2017-09-12 08:45:34
【问题描述】:
我正在处理我的拼贴项目,即员工管理。我在 sql 中有 Employee 表(crud 也是从 gii 生成的)。只有管理员有权创建员工(没有注册)。
我的问题:当我创建员工时,我也无法在用户表中保存数据,请帮助我在员工和用户表中保存数据。
提前致谢
更新:
下面是代码:
public function actionCreate() {
$model1=new Employee;
$model2=new User;
if(isset($_POST['Employee']) && isset($_POST['User']))
{
$model1->attributes=$_POST['Emoloyee'];
$model2->attributes=$_POST['User'];
$model1->save();
$model2->save();
echo 'data is saved in both tables';
}
$this->render('create',array('model1'=>$model1,model2'=>$model2));
}
【问题讨论】:
-
到目前为止你尝试了什么?
-
可以显示保存员工的代码吗?
-
公共函数 actionCreate() { $model1=new Employee; $model2=新用户; if(isset($_POST['Employee']) && isset($_POST['User'])) { $model1->attributes=$_POST['Emoloyee']; $model2->attributes=$_POST['User']; $model1->保存(); $model2->保存(); echo '数据保存在两个表中'; $this->render('create',array('model1'=>$model1,model2'=>$model2)); }
-
嗨,我的员工控制器的 Chinmay 代码如下: public function actionCreate() { $model1=new Employee; $model2=新用户; if(isset($_POST['Employee']) && isset($_POST['User'])) { $model1->attributes=$_POST['Emoloyee']; $model2->attributes=$_POST['User']; $model1->保存(); $model2->保存(); echo '数据保存在两个表中'; $this->render('create',array('model1'=>$model1,model2'=>$model2)); }
-
您可以编辑问题并将代码放在那里。 cmets部分的代码很难阅读。
标签: yii2 yii2-advanced-app yii2-user