|
|
|
<?php
|
|
|
|
|
|
|
|
namespace frontend\controllers;
|
|
|
|
|
|
|
|
use common\libs\MyLib;
|
|
|
|
use common\models\RoleT;
|
|
|
|
use common\models\UserT;
|
|
|
|
use Yii;
|
|
|
|
use yii\web\Response;
|
|
|
|
|
|
|
|
class RoleController extends BaseController
|
|
|
|
{
|
|
|
|
public $enableCsrfValidation = false;
|
|
|
|
public $layout = 'blue-main';
|
|
|
|
|
|
|
|
public function actionIndex()
|
|
|
|
{
|
|
|
|
return $this->render('index');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionIndexJson()
|
|
|
|
{
|
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
|
$items = RoleT::find()
|
|
|
|
->orderBy('id asc')
|
|
|
|
->all();
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
$data['total'] = count($items);
|
|
|
|
$data['rows'] = [];
|
|
|
|
foreach($items as $item) {
|
|
|
|
$row = $item->toArray();
|
|
|
|
$data['rows'][] = $row;
|
|
|
|
}
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionEdit()
|
|
|
|
{
|
|
|
|
$request = Yii::$app->request;
|
|
|
|
$id = $request->get('id',0);
|
|
|
|
if($id > 0) {
|
|
|
|
$info = RoleT::findOne(['id'=>$id]);
|
|
|
|
} else {
|
|
|
|
$info = new RoleT();
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->render('edit',[
|
|
|
|
'info' => $info
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionSave()
|
|
|
|
{
|
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
|
$request = Yii::$app->request;
|
|
|
|
$result = array();
|
|
|
|
$result['success'] = false;
|
|
|
|
$result['msg'] = '保存失败';
|
|
|
|
|
|
|
|
if($request->isPost) {
|
|
|
|
$id = $request->post('id',0);
|
|
|
|
$name = $request->post('name');
|
|
|
|
|
|
|
|
if($name == '') {
|
|
|
|
$result['msg'] = '请输入名称!';
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
$row = null;
|
|
|
|
if($id > 0) {
|
|
|
|
$row = RoleT::findOne(['id'=>$id]);
|
|
|
|
} else {
|
|
|
|
$row = new RoleT();
|
|
|
|
}
|
|
|
|
$row->name = $name;
|
|
|
|
$row->save();
|
|
|
|
|
|
|
|
$result['success'] = true;
|
|
|
|
$result['msg'] = '保存成功';
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function actionDelete()
|
|
|
|
{
|
|
|
|
Yii::$app->response->format = Response::FORMAT_JSON;
|
|
|
|
$request = Yii::$app->request;
|
|
|
|
$result = array();
|
|
|
|
$result['success'] = false;
|
|
|
|
$result['msg'] = '删除失败';
|
|
|
|
|
|
|
|
if($request->isPost) {
|
|
|
|
$id = $request->post('id',0);
|
|
|
|
|
|
|
|
if($id > 0) {
|
|
|
|
$row = RoleT::findOne(['id'=>$id]);
|
|
|
|
$row->delete();
|
|
|
|
|
|
|
|
$result['success'] = true;
|
|
|
|
$result['msg'] = '删除成功';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
}
|