Esempio n. 1
-1
 /**
  * @inheritdoc
  */
 public function run()
 {
     switch ($this->response) {
         case static::RESPONSE_DEPDROP:
             $post = Yii::$app->request->post('depdrop_parents');
             break;
         case static::RESPONSE_HTML:
             $post = Yii::$app->request->post();
             break;
     }
     /** @var ActiveRecord $model */
     $model = $this->controller->findModel(false);
     $model->setAttributes(array_combine($this->postAttributes, array_values($post)));
     $method = GridHelper::listName($this->listAttribute);
     $list = $model->{$method}();
     switch ($this->response) {
         case static::RESPONSE_DEPDROP:
             Yii::$app->response->format = Response::FORMAT_JSON;
             $items = [];
             foreach ($list as $id => $name) {
                 $items[] = compact('id', 'name');
             }
             return ['output' => $items, 'selected' => ''];
             break;
         case static::RESPONSE_HTML:
             return Html::activeDropDownList($model, $this->listAttribute, $list);
             break;
         default:
             throw new Exception('Undefined list type');
     }
 }