m.c. juan carlos olivares rojas. code igniter “it’s an open source web application framework...
TRANSCRIPT
![Page 1: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/1.jpg)
M.C. Juan Carlos Olivares Rojas
![Page 2: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/2.jpg)
Code Igniter
“It’s an Open Source Web Application
Framework that helps you write incredible PHP programs”
![Page 3: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/3.jpg)
Desarrollo de WebApps
• Estructura: HTML (HTML5, XHTML)
• Diseño: CSS
• Dinamismo Cliente: JavaScript
• Dinamismo Servidor: PHP*
• Datos: Base de Datos
![Page 4: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/4.jpg)
Framework MVC
![Page 5: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/5.jpg)
Flujo de Trabajo
![Page 6: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/6.jpg)
Se necesita tener
previamente instalado:
Servidor Web con soporte para
PHP, SGBD
Se recomienda instalaciones LAMP como XAMPP
Instalación
![Page 7: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/7.jpg)
Solo se copia la carpeta base que se descargo y está listo para usarse
![Page 8: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/8.jpg)
Ejecución
• Se recomienda cambiar la línea:
• $config['base_url'] = "http://example.com/";
• Por la URL de nuestro sitio.
• Simplemente se accede a nuestra URL y ya tenemos montado un sitio de ejemplo.
![Page 9: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/9.jpg)
Ejecución
![Page 10: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/10.jpg)
Programación
• Se deben generar en primera instancia los controladores, las vistas y los modelos.
• Cada uno de ellos tienen sus propias carpetas específicas dentro de la carpeta application.
• Nótese que se cuenta con ejemplos de ellos
![Page 11: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/11.jpg)
Controlador
• Derivan de la clase Controller (en la version 2.0 se usa CI_Controller)
• En ella se debe instanciar su constructor• Y definir el método index()
• Cada método deriva en una URL de acceso
![Page 12: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/12.jpg)
Estructura URL
dominio.com/controlador/method/data
<?php class Search extends Controller {[...]function recuperar($id) {
$this->load->database(); [...]}
![Page 13: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/13.jpg)
Vistas
• Las vistas están hechas de HTML.
• El controlador puede pasarle datos a través del arreglo $data[], donde cada entrada forma una variable de PHP.
• Generalmente el controlador recibe los datos del modelo
![Page 14: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/14.jpg)
Acceso a la Vista
• Las vistas se acceden desde el controlador con:
$this->load->view('helloworld_view',$data);
$this->load->library(‘email);$this->load->database();
![Page 15: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/15.jpg)
Modelo• El modelo representa la lógica de la
aplicación generalmente el acceso a los datos.
• Se deriva de la clase Model y sus métodos realizan procesos o manipulación de datos en nuestra base de datos.
![Page 16: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/16.jpg)
Acceso a BD
• Para utilizar acceso a bases de datos se necesita configurar el archivo database.php dentro de la carpeta config.
• Se debe de cargar la biblioteca de BD en el archivo autoload.php dentro de la carpeta config con la siguiente línea:
• $autoload['libraries'] = array('database');
![Page 17: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/17.jpg)
Acceso al Modelo
• Los modelos se acceden desde el controlador con:
$this->load->mode('helloworld_model'); $data['result'] = $this->helloworld_model-
>getData(); $data['page_title'] = "CI Hello World App!";
![Page 18: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/18.jpg)
Otras configuraciones
• Se recomienda cambiar el controlador predeterminado para que acceda inmediatamente, esto se hace modificando la siguiente línea del archivo route.php dentro de la carpeta config:
• $route['default_controller'] = "Helloworld"
![Page 19: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/19.jpg)
Funciones de BDfunction getData(){ $query = $this->db->get(’tabla'); if ($query->num_rows() > 0) { return $query->result(); } else{ echo 'Database is empty!'); } }}
![Page 20: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/20.jpg)
Helpers
• Son funciones de utilidad que nos permiten ahorrar trabajo
• Se cargan de la siguiente forma• $this->load->helper(‘form’);
• Se invocan como funciones normales:• <?php form-helper() ?>
![Page 21: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/21.jpg)
Cambio de index.php
• Para cambiar el molesto index.php al acceder a las URLs se necesitan configurar algunas cosas.
• En el archivo .htaccess (servidor apache) hay que agregar:
• RewriteEngine on• RewriteCond $1 !^(index\.php|images|
robots\.txt)RewriteRule ^(.*)$ ci/index.php/$1 [L]
![Page 22: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/22.jpg)
Cambio index.php• En el archivo config.php de la carpeta config se
deberán cambiar:
• $config['index_page'] = "";• $config['rewrite_short_tags'] = TRUE;
•
![Page 23: M.C. Juan Carlos Olivares Rojas. Code Igniter “It’s an Open Source Web Application Framework that helps you write incredible PHP programs”](https://reader035.vdocuments.mx/reader035/viewer/2022062315/5665b4921a28abb57c924777/html5/thumbnails/23.jpg)
¿Preguntas?
@jcolivares
/juancarlosolivaresrojas
http://antares.itmorelia.edu.mx/~jcolivares