/** * 模型添加 * */ public function actionAdCreate() { $model = new ModelType(); if (isset($_POST['ModelType'])) { $model->attributes = $_POST['ModelType']; if ($model->save()) { $this->message('success', Yii::t('admin', 'Add Success'), $this->createUrl('index')); } } $this->render('create', array('model' => $model)); }
public function findByModelName($modelName) { if (empty($modelName)) { throw new \Exception("Model name may not be empty"); } $model = $this->findSingleByAttribute('model_name', $modelName); if ($model) { return $model->id; } $model = new ModelType(); $model->model_name = $modelName; $model->save(); return $model->id; }