Пример #1
8
 /**
  * Creates a new Sucursal model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Sucursal();
     $model->create_user = Yii::$app->user->getId();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         $saved = true;
         $model->imagenes = UploadedFile::getInstances($model, 'imagenes');
         foreach ($model->imagenes as $imagen) {
             $image = new Imagen();
             $rnd = rand(0, 99999999);
             $path = Yii::$app->basePath . '/web/images';
             if (!file_exists($path)) {
                 mkdir($path, 0777);
             }
             $path = $path . '/Sucursal';
             if (!file_exists($path)) {
                 mkdir($path, 0777);
             }
             $path = $path . '/' . $model->id;
             if (!file_exists($path)) {
                 mkdir($path, 0777);
             }
             $imagen->saveAs($path . '/' . $rnd . '.' . $imagen->extension);
             $image->ur_imagen = $rnd . '.' . $imagen->extension;
             $image->save();
         }
         if ($saved) {
             return $this->redirect(['view', 'id' => $model->id]);
         }
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Imagen::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' => $this->id, 'create_user' => $this->create_user, 'create_time' => $this->create_time, 'update_user' => $this->update_user, 'update_time' => $this->update_time]);
     $query->andFilterWhere(['like', 'ur_imagen', $this->ur_imagen]);
     return $dataProvider;
 }
Пример #3
0
 /**
  * Finds the Imagen model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Imagen the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Imagen::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }