Exemple #1
0
 public function actionSearch($enviar_a = null)
 {
     $table = new Alumnos();
     $model = null;
     //$table->find()->all();
     $form = new FormSearch();
     $search = null;
     if ($form->load(Yii::$app->request->get())) {
         if ($form->validate()) {
             //Esto previene ataques del tipo xss
             $search = Html::encode($form->q);
             if ($search == "todos") {
                 $search = "";
                 $query = "SELECT * FROM alumnos WHERE p_nombre LIKE '%{$search}%' OR ";
                 $query .= "p_apellido LIKE '%{$search}%' OR servicio LIKE '%{$search}%' OR ";
                 $query .= "mail LIKE '%{$search}%' OR horario LIKE '%{$search}%'";
                 $model = $table->findBySql($query)->all();
             } else {
                 if ($search == "limpiar" || $search == "") {
                     $model = null;
                 } else {
                     $query = "SELECT * FROM alumnos WHERE p_nombre LIKE '%{$search}%' OR ";
                     $query .= "p_apellido LIKE '%{$search}%' OR servicio LIKE '%{$search}%' OR ";
                     $query .= "mail LIKE '%{$search}%' OR horario LIKE '%{$search}%'";
                     $model = $table->findBySql($query)->all();
                 }
             }
         } else {
             $form->getErrors();
         }
     }
     //$user = User::find()->where(['name' => 'CeBe'])->one();
     return $this->render('search', ['model' => $model, "form" => $form, "search" => $search, "enviar_a" => $enviar_a]);
 }
 /**
  * Lists all Form models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new FormSearch();
     if (isset($_GET['pageSize'])) {
         Yii::$app->session->set('pageSize', (int) $_GET['pageSize']);
         unset($_GET['pageSize']);
     }
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
 public function actionView()
 {
     $form = new FormSearch();
     $search = null;
     if ($form->load(Yii::$app->request->get())) {
         if ($form->validate()) {
             $search = Html::encode($form->q);
             $table = Alumnos::find()->where(["like", "id_alumno", $search])->orWhere(["like", "nombre", $search])->orWhere(["like", "apellidos", $search]);
             $count = clone $table;
             $pages = new Pagination(["pageSize" => 5, "totalCount" => $count->count()]);
             $model = $table->offset($pages->offset)->limit($pages->limit)->all();
         } else {
             $form->getErrors();
         }
     } else {
         $table = Alumnos::find();
         $count = clone $table;
         $pages = new Pagination(["pageSize" => 5, "totalCount" => $count->count()]);
         $model = $table->offset($pages->offset)->limit($pages->limit)->all();
     }
     return $this->render("view", ["model" => $model, "form" => $form, "search" => $search, "pages" => $pages]);
 }
 public function actionView()
 {
     $table = new Parvulo();
     $model = $table->find()->all();
     //Extrayendo todos los registros de la tabla parvulo
     $form = new FormSearch();
     $search = null;
     if ($form->load(Yii::$app->request->get())) {
         if ($form->validate()) {
             $search = Html::encode($form->q);
             $query = "SELECT * FROM parvulo WHERE rut_parvulo LIKE '%{$search}%'";
             //integrado el campode busqueda
             $model = $table->findBySql($query)->all();
         } else {
             $form->getErrors();
         }
     }
     return $this->render("view", ["model" => $model, "form" => $form, "search" => $search]);
 }
 public function actionViewViejo()
 {
     $table = new Alumnos();
     /* Metodo que me trae todos los registro de la tabla */
     $model = $table->find()->all();
     $form = new FormSearch();
     /* Variable que contendra la busqueda */
     $search = null;
     /* Si el formulario es envio por get*/
     if ($form->load(Yii::$app->request->get())) {
         if ($form->validate()) {
             /* Metodo encode para evitar ataques del tipo xss */
             $search = Html::encode($form->q);
             /* Consulta sql */
             $query = "SELECT * FROM alumnos WHERE id_alumno LIKE '%{$search}%' OR ";
             $query .= "nombre LIKE '%{$search}%' OR apellidos LIKE '%{$search}%'";
             /* Guardamos en la variable model los datos que nos traera la consulta */
             $model = $table->findBySql($query)->all();
         } else {
             $form->getErros();
         }
     }
     return $this->render("view", ['model' => $model, "form" => $form, "search" => $search]);
 }
 /**
  * Lists all Form models.
  * @return mixed
  */
 public function actionIndex()
 {
     $searchModel = new FormSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->queryParams);
     return $this->render('index', ['searchModel' => $searchModel, 'dataProvider' => $dataProvider]);
 }
 public function actionView()
 {
     $table = new Alumnos();
     $model = $table->find()->orderBy('clase, note_final')->all();
     $form = new FormSearch();
     $search = null;
     if ($form->load(Yii::$app->request->get())) {
         if ($form->validate()) {
             $search = Html::encode($form->q);
             #$model = $table->find()->where('id_alumno LIKE :data OR nombre LIKE :data OR apellidos LIKE :data')->addParams([":data"=>"%".$search."%"])->all();
             $table = Alumnos::find()->where(["like", "id_alumno", $search])->orWhere(["like", "nombre", $search])->orWhere(["like", "apellidos", $search]);
             // clonar el objeto $table una vez hecha la consulta
             // se crea la instancia para la paginacion
             $count = clone $table;
             $pages = new Pagination(["pageSize" => 2, "totalCount" => $count->count()]);
             $model = $table->offset($pages->offset)->limit($pages->limit)->all();
         } else {
             $form->getErrors;
         }
     } else {
         $table = Alumnos::find();
         $count = clone $table;
         $pages = new Pagination(["pageSize" => 2, "totalCount" => $count->count()]);
         $model = $table->offset($pages->offset)->limit($pages->limit)->all();
     }
     return $this->render("view", ["model" => $model, "form" => $form, "search" => $search, "pages" => $pages]);
 }