/**
  * Updates an existing Sanpham 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);
     $list = Loaisanpham::find()->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect('index.php?r=sanpham%2Findex');
     } else {
         return $this->render('update', ['model' => $model, 'list' => $list]);
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Loaisanpham::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id_loaisanpham' => $this->id_loaisanpham, 'record_status' => $this->record_status]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Beispiel #3
0
 public function actionCreate()
 {
     $lstLine = Loaisanpham::find()->where(['between', 'status', 1, 4])->all();
     $model = new Sanpham();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $model->status = 1;
             $model->save();
             $model->file = UploadedFile::getInstance($model, 'file');
             if ($model->file) {
                 $id = $model->id_sp;
                 $imageName = "loaisanpham_" . $id . '_' . getdate()[0];
                 $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension);
                 $station = Sanpham::findOne($id);
                 $station->sp_anh = '@web/uploads/' . $imageName . '.' . $model->file->extension;
                 $station->save();
             }
             return $this->redirect(['sanpham/index']);
         }
     } else {
         return $this->render('create', ['user' => $model, 'listLine' => $lstLine]);
     }
 }
 /**
  * Lists all Loaisanpham models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Loaisanpham::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
 public function actionIndex()
 {
     $lst = Loaisanpham::find()->where(['between', 'status', 1, 4])->all();
     //var_dump($lst);die;
     return $this->render('index', ['lst' => $lst]);
 }