我有表USR
和ORGANIZATION
:
USR表
|ID | ID_APP | NAMA_APP|
组织表
|ID | NAMA |
我尝试通过ID(关系)从USR
向ORGANIZATION
表(ID_APP和NAMA_APP)插入数据。这是我的代码:
UsersController:
public function actionUpdate($id)
{
$model = $this->findModel($id);
if (Yii::$app->request->post()) {
try {
$state = true;
$data = Yii::$app->request->post();
$transaction = Yii::$app->db->beginTransaction();
$model->ID_APP = $data['USR']['ID_APP'];
$model->NAMA_APP = $data['USR']['NAMA_APP'];
if (!$model->save()) {
$ErrorMessage = $model->getErrorMessage($model->getErrors());
throw new Exception($ErrorMessage);
}
$transaction->commit();
$message = "Success update Application ";
} catch (Exception $e) {
$state = false;
$transaction->rollback();
$message = $e->getMessage();
}
if ($state) {
Yii::$app->session->setFlash('successApplication', $message);
return $this->redirect(['view', 'id' => $model->ID]);
} else {
Yii::$app->session->setFlash('errorApplication', $message);
return $this->render('view', ['id' => $model->ID]);
}
} else {
return $this->render('update', [
'model' => $model,
]);
}
}
我的观点:
<?php $org = \app\models\ORGANIZATION::find()->all(); ?>
<?= $form->field($model, 'ID_APP')->dropDownList(
ArrayHelper::map($org,'ID', 'NAMA'))->label('ID APP') ?>
我还是php
和yii2
框架的初学者如何从NAMA(USR
)获取NAMA_APP(ORGANIZATION
表)?
答案 0 :(得分:0)
基于您的观点,假设您发布了ID_APP并需要在USR中为分离的商店检索NAMA_APP