/**
  * Creates a new Carpeta model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Carpeta();
     $imagen = new Imagen();
     $imagen->load(Yii::$app->request->post());
     if ($model->load(Yii::$app->request->post())) {
         $model->save();
         $imagen->imagen = UploadedFile::getInstance($imagen, 'imagen');
         $imagen->dir = 'imagenes/' . $model->nombre . $imagen->imagen->baseName . '.' . $imagen->imagen->extension;
         $model->link("idPerfil", Yii::$app->user->identity->idPerfil);
         $imagen->save();
         $imagen->link('idCarpeta', $model);
         $imagen->imagen->saveAs($imagen->dir);
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'imagen' => $imagen]);
     }
 }
Example #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Imagen::find();
     // add conditions that should always apply here
     $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;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'id_carpeta' => $this->id_carpeta]);
     $query->andFilterWhere(['like', 'dir', $this->dir]);
     return $dataProvider;
 }
 /**
  * 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.');
     }
 }
Example #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getImagens()
 {
     return $this->hasMany(Imagen::className(), ['id_carpeta' => 'id']);
 }