informatica:programacion:php:frameworks:codeigniter_3
Diferencias
Muestra las diferencias entre dos versiones de la página.
| Ambos lados, revisión anteriorRevisión previaPróxima revisión | Revisión previa | ||
| informatica:programacion:php:frameworks:codeigniter_3 [2023/02/15 10:40] – tempwin | informatica:programacion:php:frameworks:codeigniter_3 [2024/04/02 10:30] (actual) – [Envío e-mail] tempwin | ||
|---|---|---|---|
| Línea 1: | Línea 1: | ||
| ====== CodeIgniter 3 ====== | ====== CodeIgniter 3 ====== | ||
| - | Framework de PHP. | + | Framework de [[informatica: |
| * [[https:// | * [[https:// | ||
| Línea 115: | Línea 115: | ||
| Utilidades para interactuar con la base de datos | Utilidades para interactuar con la base de datos | ||
| + | |||
| + | ==== Actualizar si existe, insertar si no ==== | ||
| + | |||
| + | <code php> | ||
| + | $this-> | ||
| + | </ | ||
| + | |||
| + | Ese método ejecuta una sentencia '' | ||
| + | |||
| + | Ejemplo: | ||
| + | |||
| + | <code php> | ||
| + | $data = array( | ||
| + | ' | ||
| + | ' | ||
| + | ' | ||
| + | ); | ||
| + | |||
| + | $this-> | ||
| + | |||
| + | // Ejecuta: REPLACE INTO mytable (title, name, date) VALUES ('My title', | ||
| + | </ | ||
| + | |||
| ==== Múltiples condiciones en WHERE ==== | ==== Múltiples condiciones en WHERE ==== | ||
| Línea 134: | Línea 157: | ||
| </ | </ | ||
| + | ==== WHERE con varios valores para el mismo campo ==== | ||
| + | |||
| + | <code php> | ||
| + | $colores = [" | ||
| + | $this-> | ||
| + | </ | ||
| + | |||
| + | Lo que hace es : | ||
| + | |||
| + | <code mysql> | ||
| + | WHERE color IN (' | ||
| + | </ | ||
| + | |||
| + | Si lo quisiéramos negar, usaríamos '' | ||
| + | |||
| + | <code php> | ||
| + | $colores = [" | ||
| + | $this-> | ||
| + | </ | ||
| + | |||
| + | Lo que hace es : | ||
| + | |||
| + | <code mysql> | ||
| + | WHERE color NOT IN (' | ||
| + | </ | ||
| ===== Utilidades ===== | ===== Utilidades ===== | ||
| Línea 158: | Línea 206: | ||
| * [[https:// | * [[https:// | ||
| + | ===== Bibliotecas ===== | ||
| + | |||
| + | ==== Envío e-mail ==== | ||
| + | |||
| + | La [[https:// | ||
| + | |||
| + | Cargar la biblioteca con los métodos para el envío de e-mails: | ||
| + | |||
| + | <code php> | ||
| + | $this-> | ||
| + | </ | ||
| + | |||
| + | Configuración: | ||
| + | |||
| + | <code php> | ||
| + | // Configuración email para SMTP | ||
| + | $config[" | ||
| + | $config[" | ||
| + | $config[" | ||
| + | $config[" | ||
| + | $config[" | ||
| + | $config[" | ||
| + | $config[" | ||
| + | |||
| + | // Aplica configuración: | ||
| + | $this-> | ||
| + | </ | ||
| + | |||
| + | * [[https:// | ||
| + | |||
| + | Composición y envío de e-mail: | ||
| + | |||
| + | <code php> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | $this-> | ||
| + | </ | ||
| + | |||
| + | Depuración: | ||
| + | |||
| + | <code php> | ||
| + | // You need to pass FALSE while sending in order for the email data | ||
| + | // to not be cleared - if that happens, print_debugger() would have | ||
| + | // nothing to output. | ||
| + | if (!$this-> | ||
| + | echo $this-> | ||
| + | } | ||
| + | </ | ||
| + | ==== Lectura CSV ==== | ||
| + | |||
| + | Biblioteca personalizada: | ||
| + | |||
| + | <code php> | ||
| + | <?php if (!defined(' | ||
| + | |||
| + | /** | ||
| + | * CSVReader Class | ||
| + | * | ||
| + | * Allows to retrieve a CSV file content as a two dimensional array. | ||
| + | * Optionally, the first text line may contains the column names to | ||
| + | * be used to retrieve fields values (default). | ||
| + | */ | ||
| + | class CSVReader | ||
| + | { | ||
| + | |||
| + | var $fields; // columns names retrieved after parsing | ||
| + | var $separator = ','; | ||
| + | var $enclosure = '"'; | ||
| + | |||
| + | var $max_row_size = 4096; // maximum row size to be used for decoding | ||
| + | |||
| + | /** | ||
| + | * Parse a file containing CSV formatted data. | ||
| + | * | ||
| + | * @access | ||
| + | * @param | ||
| + | * @param | ||
| + | * @return | ||
| + | */ | ||
| + | function parse_file($p_Filepath, | ||
| + | { | ||
| + | $content = false; | ||
| + | $file = fopen($p_Filepath, | ||
| + | |||
| + | if ($p_NamedFields) { | ||
| + | $this-> | ||
| + | } | ||
| + | |||
| + | while ( ($row = fgetcsv($file, | ||
| + | if ( $row[0] != null ) { // skip empty lines | ||
| + | if ( !$content ) { | ||
| + | $content = array(); | ||
| + | } | ||
| + | |||
| + | if ( $p_NamedFields ) { | ||
| + | $items = array(); | ||
| + | |||
| + | foreach ( $this-> | ||
| + | if ( isset($row[$id]) ) { | ||
| + | $items[$field] = $row[$id]; | ||
| + | } | ||
| + | } | ||
| + | $content[] = $items; | ||
| + | } else { | ||
| + | $content[] = $row; | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | |||
| + | fclose($file); | ||
| + | return $content; | ||
| + | } | ||
| + | |||
| + | } | ||
| + | |||
| + | /* Location: ./ | ||
| + | </ | ||
| + | |||
| + | Para usarla: | ||
| + | |||
| + | <code php> | ||
| + | $this-> | ||
| + | $csvData = $this-> | ||
| + | </ | ||
| ===== Excel ===== | ===== Excel ===== | ||
| * [[https:// | * [[https:// | ||
| + | * [[https:// | ||
informatica/programacion/php/frameworks/codeigniter_3.1676454003.txt.gz · Última modificación: por tempwin
