|
|
@ -12,13 +12,12 @@ use yii\filters\VerbFilter; |
|
|
|
/** |
|
|
|
* CategoryController implements the CRUD actions for Category model. |
|
|
|
*/ |
|
|
|
class CategoryController extends Controller |
|
|
|
{ |
|
|
|
class CategoryController extends Controller { |
|
|
|
|
|
|
|
/** |
|
|
|
* {@inheritdoc} |
|
|
|
*/ |
|
|
|
public function behaviors() |
|
|
|
{ |
|
|
|
public function behaviors() { |
|
|
|
return [ |
|
|
|
'verbs' => [ |
|
|
|
'class' => VerbFilter::className(), |
|
|
@ -33,14 +32,13 @@ class CategoryController extends Controller |
|
|
|
* Lists all Category models. |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionIndex() |
|
|
|
{ |
|
|
|
public function actionIndex() { |
|
|
|
$searchModel = new CategorySearch(); |
|
|
|
$dataProvider = $searchModel->search(Yii::$app->request->queryParams); |
|
|
|
|
|
|
|
return $this->render('index', [ |
|
|
|
'searchModel' => $searchModel, |
|
|
|
'dataProvider' => $dataProvider, |
|
|
|
'searchModel' => $searchModel, |
|
|
|
'dataProvider' => $dataProvider, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
@ -50,10 +48,9 @@ class CategoryController extends Controller |
|
|
|
* @return mixed |
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
|
|
|
*/ |
|
|
|
public function actionView($id) |
|
|
|
{ |
|
|
|
public function actionView($id) { |
|
|
|
return $this->render('view', [ |
|
|
|
'model' => $this->findModel($id), |
|
|
|
'model' => $this->findModel($id), |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
@ -62,8 +59,7 @@ class CategoryController extends Controller |
|
|
|
* If creation is successful, the browser will be redirected to the 'view' page. |
|
|
|
* @return mixed |
|
|
|
*/ |
|
|
|
public function actionCreate() |
|
|
|
{ |
|
|
|
public function actionCreate() { |
|
|
|
$model = new Category(); |
|
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
|
@ -71,7 +67,7 @@ class CategoryController extends Controller |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('create', [ |
|
|
|
'model' => $model, |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
@ -82,8 +78,7 @@ class CategoryController extends Controller |
|
|
|
* @return mixed |
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
|
|
|
*/ |
|
|
|
public function actionUpdate($id) |
|
|
|
{ |
|
|
|
public function actionUpdate($id) { |
|
|
|
$model = $this->findModel($id); |
|
|
|
|
|
|
|
if ($model->load(Yii::$app->request->post()) && $model->save()) { |
|
|
@ -91,7 +86,7 @@ class CategoryController extends Controller |
|
|
|
} |
|
|
|
|
|
|
|
return $this->render('update', [ |
|
|
|
'model' => $model, |
|
|
|
'model' => $model, |
|
|
|
]); |
|
|
|
} |
|
|
|
|
|
|
@ -102,13 +97,20 @@ class CategoryController extends Controller |
|
|
|
* @return mixed |
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
|
|
|
*/ |
|
|
|
public function actionDelete($id) |
|
|
|
{ |
|
|
|
public function actionDelete($id) { |
|
|
|
$this->findModel($id)->delete(); |
|
|
|
|
|
|
|
return $this->redirect(['index']); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* |
|
|
|
*/ |
|
|
|
public function actionDeletes() { |
|
|
|
//获取前端post的记录id
|
|
|
|
$ids = Yii::$app->request->post('ids'); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* Finds the Category model based on its primary key value. |
|
|
|
* If the model is not found, a 404 HTTP exception will be thrown. |
|
|
@ -116,12 +118,12 @@ class CategoryController extends Controller |
|
|
|
* @return Category the loaded model |
|
|
|
* @throws NotFoundHttpException if the model cannot be found |
|
|
|
*/ |
|
|
|
protected function findModel($id) |
|
|
|
{ |
|
|
|
protected function findModel($id) { |
|
|
|
if (($model = Category::findOne($id)) !== null) { |
|
|
|
return $model; |
|
|
|
} |
|
|
|
|
|
|
|
throw new NotFoundHttpException('The requested page does not exist.'); |
|
|
|
} |
|
|
|
|
|
|
|
} |