/** * 创建知识分类 */ public function actionCreate() { $model = new ShopClass(); if (isset($_POST) && !empty($_POST)) { $model->name = $_POST['ShopClass']['name']; $model->create_time = time(); if ($model->save()) { return $this->redirect(['index']); } else { Yii::$app->getErrorHandler(); } } return $this->render('create', ['model' => $model]); }
/** * Creates a new Course model. * If creation is successful, the browser will be redirected to the 'view' page. * @return mixed */ public function actionCreate() { $model = new Course(); $type = ShopClass::find()->all(); foreach ($type as $k => $v) { $arr[$v['id']] = $v['name']; } if (!empty(Yii::$app->request->post())) { $params = Yii::$app->request->post(); $model->title = $params['Course']['title']; $model->explain = $params['Course']['explain']; $model->type = $params['Course']['type']; $model->log = $params['Course']['log']; $model->thumb = $params['Course']['thumb']; $model->content = $params['Course']['content']; $model->create_time = time(); if ($model->save()) { $this->redirect(['index']); } } return $this->renderPartial('create', ['model' => $model, 'arr' => $arr]); }