public function addCat($name, $sort, $desc) { //用户名已存在 if (ProductCategory::findOne($name)) { return false; } $model = new ProductCategory(); $model->categoryName = $name; $model->sort = $sort; $model->desc = $desc; $model->addTime = date('Y-m-d H:i:s', time()); $model->addUser = \Yii::$app->session->get(Variable::$session_userId_str); if ($model->save() > 0) { return true; } return false; }
/** * Finds the ProductCategory model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return ProductCategory the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = ProductCategory::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }