/**
  * 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]);
     }
 }
Exemplo n.º 2
0
 /**
  * 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;
 }
Exemplo n.º 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]);
     }
 }
Exemplo n.º 4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdLoaisanpham()
 {
     return $this->hasOne(Loaisanpham::className(), ['id_loaisanpham' => 'id_loaisanpham']);
 }
Exemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getLoaisanpham()
 {
     return $this->hasOne(Loaisanpham::className(), ['loaisanpham_id' => 'loaisanpham_id']);
 }
Exemplo n.º 6
0
 /**
  * Finds the Loaisanpham model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Loaisanpham the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Loaisanpham::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
Exemplo n.º 7
0
 public function actionPreview($id)
 {
     $model = Loaisanpham::findOne($id);
     return $this->render('preview', ['model' => $model]);
 }