示例#1
0
 public function init()
 {
     if ($this->ajaxResponseFormatter === null) {
         $this->ajaxResponseFormatter = function ($action) {
             $results = [];
             foreach ($action->collection->models as $k => $v) {
                 $results[$k] = ArrayHelper::toArray($v, $this->returnOptions);
             }
             return $results;
         };
     }
     parent::init();
 }
示例#2
0
 /** {@inheritdoc} */
 protected function getDefaultRules()
 {
     return array_merge(parent::getDefaultRules(), ['POST xeditable' => ['class' => XEditableAction::class], 'GET html | POST selection' => ['class' => RenderAction::class, 'data' => $this->data, 'view' => $this->view, 'params' => function ($action) {
         $models = $this->fetchModels();
         foreach ($models as $model) {
             $model->scenario = $this->scenario;
         }
         return ['models' => $models, 'model' => reset($models)];
     }], 'GET ajax' => ['success' => ['class' => RenderAjaxAction::class, 'data' => $this->data, 'view' => $this->view, 'params' => function ($action) {
         $models = $this->fetchModels();
         foreach ($models as $model) {
             $model->scenario = $this->scenario;
         }
         return ['models' => $models, 'model' => reset($models)];
     }]], 'POST html' => ['save' => true, 'success' => ['class' => RedirectAction::class, 'url' => function ($action) {
         return $action->collection->count() > 1 ? $action->controller->getSearchUrl(['id_in' => $action->collection->ids]) : $action->controller->getActionUrl('view', ['id' => $action->collection->first->id]);
     }], 'error' => ['class' => RenderAction::class, 'view' => $this->view, 'data' => $this->data, 'params' => function ($action) {
         return ['model' => $action->collection->first, 'models' => $action->collection->models];
     }]], 'POST pjax' => ['save' => true, 'success' => ['class' => ProxyAction::class, 'action' => 'view', 'params' => function ($action, $model) {
         return ['id' => $model->id];
     }]], 'POST ajax' => ['save' => true, 'success' => ['class' => RedirectAction::class, 'url' => function ($action) {
         return $action->collection->count() > 1 ? $action->controller->getSearchUrl(['id_in' => $action->collection->ids]) : $action->controller->getActionUrl('view', ['id' => $action->collection->first->id]);
     }]]]);
 }