public function actionIndex()
 {
     $query = Product::find();
     $searchModel = new ProductSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
Beispiel #2
0
 /**
  * Updates an existing Product model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public function actionUpdate($id)
 {
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post())) {
         $model->last_update = $model->created_time;
         $model->user_id = \Yii::$app->user->id;
         Util::save($model);
     }
     $searchModel = new ProductSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('update', ['model' => $model, 'searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
 /**
  * Lists all Product models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new ProductSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     $product = Product::find()->orderBy('id')->asArray()->all();
     if (Yii::$app->request->post()) {
         // validate if there is a editable input saved via AJAX
         if (Yii::$app->request->post('hasEditable')) {
             $id = Yii::$app->request->post('editableKey');
             $modelEdit = $this->findModel($id);
             //$model = $this->findOne($atid);
             // store a default json response as desired by editable
             $out = Json::encode(['output' => '', 'message' => '']);
             // fetch the first entry in posted data (there should
             // only be one entry anyway in this array for an
             // editable submission)
             // - $posted is the posted data for Book without any indexes
             // - $post is the converted array for single model validation
             $post = [];
             $posted = current($_POST['Product']);
             $post['Product'] = $posted;
             var_dump($post);
             exit;
             // load model like any single model validation
             if ($modelEdit->load($post)) {
                 // can save model or do something before saving model
                 $modelEdit->updated_at = new Expression('NOW()');
                 $modelEdit->updated_at = new Expression('NOW()');
                 if ($modelEdit->thumbnail) {
                     /*$thumb = $model->uploadThumbnail();
                       if ($thumb !== false) {
                           $path = $model->getThumbnail();
                           $thumb->saveAs($path);
                       }*/
                 }
                 $modelEdit->save();
                 // custom output to return to be displayed as the editable grid cell
                 // data. Normally this is empty - whereby whatever value is edited by
                 // in the input by user is updated automatically.
                 $output = '';
                 // specific use case where you need to validate a specific
                 // editable column posted when you have more than one
                 // EditableColumn in the grid view. We evaluate here a
                 // check to see if buy_amount was posted for the Book model
                 if (isset($posted['title'])) {
                     //$output =  Yii::$app->formatter->asNText($modelEdit->parent_id);
                     $output = $modelEdit->title;
                 }
                 if (isset($posted['status'])) {
                     //$output =  Yii::$app->formatter->asNText($modelEdit->parent_id);
                     $output = $modelEdit->status ? Yii::t('db', 'Active') : Yii::t('db', 'Inactive');
                 }
                 /* if (isset($posted['thumbnail'])) {
                       //$output =  Yii::$app->formatter->asNText($modelEdit->parent_id);
                        $output = $modelEdit->getThumbnailUrl();
                    } */
                 // similarly you can check if the name attribute was posted as well
                 // if (isset($posted['name'])) {
                 //   $output =  ''; // process as you need
                 // }
                 $out = Json::encode(['output' => $output, 'message' => '']);
             }
             // return ajax json encoded response and exit
             echo $out;
             return;
         }
     }
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }