public function phanloai() { return $this->hasOne(Phanloai::className(), ['id' => 'id_PhanLoai']); }
use yii\helpers\Html; use yii\widgets\ActiveForm; use app\models\Phanloai; use yii\helpers\ArrayHelper; /* @var $this yii\web\View */ /* @var $model app\models\UrlAnh */ /* @var $form yii\widgets\ActiveForm */ ?> <div class="url-anh-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'id_PhanLoai')->dropDownList(ArrayHelper::map(Phanloai::find()->all(), 'id', 'TenPhanLoai')); ?> <?php echo $form->field($model, 'URL')->textarea(['rows' => 6]); ?> <div class="form-group"> <?php echo Html::submitButton($model->isNewRecord ? 'Thêm' : 'Sửa', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']); ?> </div> <?php ActiveForm::end(); ?>
/** * Finds the Phanloai model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return Phanloai the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Phanloai::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }