Beispiel #1
0
 /**
  * action 运行入口
  * 
  * @access public
  * @return mixed
  */
 public function run()
 {
     $controller = $this->getController();
     $methodName = preg_split("/_(?=(save|del|edit)\$)/i", $this->getId());
     if (count($methodName) == 2) {
         $op = $methodName[1];
         $modelName = $methodName[0];
     } else {
         $op = $methodName[0];
         $modelName = $controller->getId();
     }
     $operator = array('save' => 'save', 'del' => 'delete', 'edit' => 'find');
     //如果配制文件存在curd函数自动进行处理
     if ($controller->getAutoActionRight() && array_key_exists($op, $operator)) {
         if ($op == 'save') {
             $pre_validator = $modelName . '_validator';
             if (method_exists($controller, $pre_validator)) {
                 $validator = $controller->{$pre_validator}();
                 if (is_array($validator)) {
                     $data = Req::args() + array('validator' => $validator);
                     $controller->redirect($modelName . '_edit', false, $data);
                     exit;
                 }
             }
         }
         $model = new Model($modelName);
         $data = $model->data(Req::args())->{$operator}[$op]();
         switch ($op) {
             case 'save':
                 if ($data !== false) {
                     $controller->redirect($modelName . '_list');
                 } else {
                     $controller->redirect($modelName . '_edit', null, false, array('form' => $model->find()));
                 }
                 break;
             case 'del':
                 $controller->redirect($modelName . '_list');
                 break;
             case 'edit':
                 $data = isset($data) ? $data : array();
                 $controller->redirect($modelName . '_edit', false, $data);
                 break;
         }
     } else {
         $action = new ViewAction($controller, $this->getId());
         $action->run();
         //exit;
     }
 }
 /** {@inheritdoc} */
 protected function getDefaultRules()
 {
     return array_merge(parent::getDefaultRules(), ['ajax' => ['save' => true, 'flash' => false, 'success' => ['class' => RenderAjaxAction::class, 'view' => $this->view, 'data' => function () {
         return $this->prepareData();
     }, 'params' => function () {
         foreach ($this->collection->models as $model) {
             $model->scenario = $this->scenario;
         }
         return ['models' => $this->collection->models, 'model' => $this->collection->first];
     }]]]);
 }
Beispiel #3
0
 /**
  * @return array
  */
 public function actions()
 {
     return ['index' => ['class' => IndexAction::className(), 'modelClass' => $this->modelClass], 'view' => ['class' => ViewAction::className(), 'modelClass' => $this->modelClass], 'create' => ['class' => CreateAction::className(), 'modelClass' => $this->modelClass], 'update' => ['class' => UpdateAction::className(), 'modelClass' => $this->modelClass], 'delete' => ['class' => DeleteAction::className(), 'modelClass' => $this->modelClass], 'search' => ['class' => SearchAction::className(), 'modelClass' => $this->modelClass]];
 }