Diferencia entre revisiones de «English Manual KumbiaPHP Framework 1.0 Index»
Línea 262: | Línea 262: | ||
== redirect($url, $seconds=0.5) == | == redirect($url, $seconds=0.5) == | ||
− | + | Wait $seconds, then redirect to another url. | |
'''Example:''' | '''Example:''' | ||
Línea 363: | Línea 363: | ||
== is_alnum($value) == | == is_alnum($value) == | ||
− | Checks if $value is alphanumeric. Useful | + | Checks if $value is alphanumeric. Useful for user input validation. |
<?php | <?php | ||
Línea 383: | Línea 383: | ||
* $record, ActiveRecord or a string ActiveRecord record to load. If the parameter is a string then it must be a name of a model. | * $record, ActiveRecord or a string ActiveRecord record to load. If the parameter is a string then it must be a name of a model. | ||
* $args, optional parameters: | * $args, optional parameters: | ||
− | + | ** field: comma separated field names to load | |
− | + | ** except: comma separated field name to NOT load. | |
− | + | ** suffix: suffix for the attribute in the controller | |
− | + | ** preffix: preffix for the attribute in the controller | |
− | + | '''Examples''' | |
− | $ | + | '''Example 1''' |
− | $this->load_record($ | + | $user = $this->User->find(1); |
+ | $this->load_record($user); | ||
− | + | '''Example 2''' | |
− | $ | + | $user = $this->User->find(1); |
− | $this->load_record($ | + | $this->load_record($user, 'except: id, sex'); |
− | + | '''Example 3''' | |
− | $ | + | $user = $this->User->find(1); |
− | $this->load_record($ | + | $this->load_record($user, 'field: name, lastname'); |
− | + | '''Example 4''' | |
− | $ | + | $user = $this->User->find(1); |
− | $this->load_record($ | + | $this->load_record($user, 'preffix: c_'); |
− | + | '''Example 5''' | |
− | $this->load_record(' | + | $this->load_record('User'); |
− | + | '''Example 6''' | |
− | $this->load_record(' | + | $this->load_record('User', 'field: name,lastname'); |
− | == is_numeric($ | + | == is_numeric($value) == |
− | + | Checks if $value is numeric. This method is useful for user input validation. | |
− | <?php | + | '''Example''' |
− | class | + | <?php |
− | function | + | class TestController extends ApplicationController { |
− | $ | + | function add(){ |
− | if($this->is_numeric($ | + | $price = $this->request("price"); |
− | Flash::error( | + | if($this->is_numeric($price)==false){ |
+ | Flash::error(“Ivalid price input”); | ||
return; | return; | ||
} | } | ||
Línea 424: | Línea 426: | ||
} | } | ||
} | } | ||
− | ?> | + | ?> |
===[[Obtener valores desde el controller]] === | ===[[Obtener valores desde el controller]] === |
Revisión del 12:24 18 oct 2009
This manual is an english port of Manual Kumbia PHP Framework. It is work in progress. You are free to help to improve it.
Until the work is finished, the manual will have spanish text mixed with english text. You are free to help us with the translation :-).
Sumario
- 1 AGRADECIMIENTOS
- 2 PREFACIO
- 3 GETTING STARTED WITH KUMBIA PHP FRAMEWORK
- 4 WORKING WITH KUMBIA PHP FRAMEWORK
- 5 MODELOS
- 6 APPLICATION CONTROLLER
- 7 ApplicationController Class Methods
- 7.1 render($view)
- 7.2 redirect($url, $seconds=0.5)
- 7.3 post($value)
- 7.4 get($value)
- 7.5 request($value)
- 7.6 render_partial($name)
- 7.7 route_to([params: value])
- 7.8 redirect($url_controlador)
- 7.9 cache_layout($minutes)
- 7.10 not_found($controller, $action) =
- 7.11 set_response($type)
- 7.12 is_alnum($value)
- 7.13 load_record($record, $args...)
- 8 VISTAS Y HELPERS
- 9 AJAX
- 10 EXTENSIONS (Módulos extras de KumbiaPHP)
- 11 GENERADOR DE FORMULARIOS
- 12 EJEMPLOS
- 13 GLOSARIO
AGRADECIMIENTOS
Este manual es para agradecer a quienes con su tiempo y apoyo en gran o en poca medida han ayudado a que este framework sea cada día mejor. A todos ellos Gracias Totales: Andres Felipe Gutierrez gutierrezandresfelipe@gmail.com Deivinson Tejeda deivinsontejeda@kumbiaphp.com Emilio Silveira emilio.rst@kumbiaphp.com César Caballero aka Phillipo phillipo@kumbiaphp.com Y a toda la comunidad que rodea a Kumbia, con sus preguntas, notificaciones de errores(Bug's), aportaciones, etc...
PREFACIO
- Sobre este libro
- Sobre Kumbia
- Sobre la comunidad
- Historia de Kumbia
- Que aporta Kumbia
- ¿Porque usar Kumbia?
- Modelo, Vista, Controlador (MVC)
GETTING STARTED WITH KUMBIA PHP FRAMEWORK
Instalar Kumbia
- Requisitos
- Descargar Kumbia
- Configuración de módulos (Apache, PHP y bbdd)
- Configurar XAMPP
- Configurar Apache2Triad
- Verificar la instalación de Kumbia
Kumbia Structure
Características avanzadas
- ¡Parámetros con Nombre!
- Obtener valores en una aplicación Kumbia
- Uso de Paquetes (Namespaces)
- Programación modular
Primera Aplicación en Kumbia
- Creando una nueva aplicación
- Hola Kumbia
- Kumbia URLS
- Nuestra Primera Acción
- Agregando más Contenido
- Repitiendo la Historia
WORKING WITH KUMBIA PHP FRAMEWORK
MODELOS
- Introducción
- ¿Por qué usar una capa de Abstracción?
- Capa de Abstracción Independiente en Kumbia
- Adaptadores Kumbia
- Esquema de Acceso a BB.DD en Kumbia
- Modelos
ACTIVE RECORD
- Ventajas del ActiveRecord
- Crear un Modelo en Kumbia PHP Framework
- Columnas y Atributos
- Llaves Primarias y el uso de IDs
CRUD: Create, Read, Update, Delete
- Creando Registros
- Consultando Registros
- El poderoso Find
- Promedio, Contando, Sumando, Mínimo y Máximo
- Actualizando Registros existentes
- Borrando Registros
- Propiedades Soportadas
Convenciones en ActiveRecord
Convenciones para RDBMs
ACTIVE RECORD API
This is a reference of the methods in ActiveRecord class sorted in alphabetic order:
Consultas
Métodos para hacer consulta de Registros:
- distinct
- find_all_by_sql(string $sql)
- find_by_sql(string $sql)
- find_first
- find
- select_one(string $select query)
- select_one(string $select query) (static)
- exists
- find_all_by
- find_by_*campo*
- find_all_by_*campo*
Conteos y Sumatorias
Promedios, Máximo y Mínimo
Creación-Actualización-Borrado de Registros
Validación
- validates_presence_of
- validates_length_of
- validates_numericality_of
- validates_email_in
- validates_uniqueness_of
- validates_date_in
- validates_format_of
Transacciones
Otros Métodos
Callbacks ActiveRecord
- Introduccion
- before_validation
- before_validation_on_create
- before_validation_on_update
- after_validation_on_create
- after_validation_on_update
- after_validation
- before_save
- before_update
- before_create
- after_update
- after_create
- after_save
- before_delete
- after_delete
Asociaciones
- Introducción
- Pertenece (belongs_to)
- Tiene un (has_one)
- Tiene muchos (has_many)
- Tiene y pertenece a muchos (has_and_belongs_to_many)
Paginadores
APPLICATION CONTROLLER
Métodos de la Clase ApplicationController
This class has several useful methods to work with controllers.
ApplicationController Class Methods
This class has several useful methods to work with controllers.
render($view)
Shows a view belonging to the same controller.
Example:
<?php class ProductsController extends ApplicationController { function index(){ $this->render('list'); } } //end of class ?>
In this case, the view views/products/list.phtml will be rendered.
redirect($url, $seconds=0.5)
Wait $seconds, then redirect to another url.
Example:
<?php class ProductsController extends ApplicationController { function index(){ $this->redirect('tickets/new', 2); } } ?>
The browser will go to tickets/new 2 seconds later
post($value)
Object oriented access to $_POST[$value].
get($value)
Object oriented access to $_GET[$value].
request($value)
Object oriented access to $_REQUEST[$value].
render_partial($name)
Render the partial view belonging to the same controller. Example:
Example:
<?php class ProductsController extends ApplicationController { function index(){ $this->render_partial('show_menu'); }//end of method }//end of class ?>
The above example will output the partial view views/products/_show_menu.phtml
route_to([params: value])
Redirect from a controller to another or from an action to another. The parameters are:
- controller: Destination controller to do the redirect.
- action: Destination action to do the redirect
- id: route id
Example:
return $this->route_to("controller: clients", "action: query", "id:1");
The redirects are internal ones, meaning the users will not realize they are been redirected.
redirect($url_controlador)
Do a redirect to another controller or action using HTTP. This is a "real" redirect to another HTML page. The URL page changes in the user browser.
Example:
$this->redirect("/products/query");
cache_layout($minutes)
Cache the view views/layout/ belonging to the controller for $minutes.
not_found($controller, $action) =
Optional method. It could be defined in any controller. If not_found method is defined then it will be called every time some action is not found. This is useful to process this kind of errors.
Example
<?php class TestController extends ApplicationController { function index(){ $this->render_text("This is the index"); } function not_found($controller, $action){ Flash::error("I am sorry. The action $action is not defined, redirecting to index..."); return $this->route_to('action: index'); } } ?>
Note: There is in the 0.5 version a default view views/not_found.phtml with the same behaviour for the whole application. If not_found method is not implemented in a controller, the views/not_found.phtml actionn will be executed. Using this default action speeds up the development.
set_response($type)
Set the controlled generated answer type.
If $type is "view" then kumbiaPHP will output the view only without layout, template or any html header. This is useful to generate AJAX or PDF output.
Another $type value is "XML".
Example
<?php class TestController extends ApplicationController { function accion_ajax(){ $this->set_response("view"); } } ?>
is_alnum($value)
Checks if $value is alphanumeric. Useful for user input validation.
<?php class TestController extends ApplicationController { function add(){ $price = $this->request("price"); if($this->is_alnum($price)==false){ Flash::error("price has not a valid value"); return; } /* ..*/ } } ?>
load_record($record, $args...)
Load the fields in a ActiveRecord record like controller attributes. The parameters are:
- $record, ActiveRecord or a string ActiveRecord record to load. If the parameter is a string then it must be a name of a model.
- $args, optional parameters:
- field: comma separated field names to load
- except: comma separated field name to NOT load.
- suffix: suffix for the attribute in the controller
- preffix: preffix for the attribute in the controller
Examples Example 1
$user = $this->User->find(1); $this->load_record($user);
Example 2
$user = $this->User->find(1); $this->load_record($user, 'except: id, sex');
Example 3
$user = $this->User->find(1); $this->load_record($user, 'field: name, lastname');
Example 4
$user = $this->User->find(1); $this->load_record($user, 'preffix: c_');
Example 5
$this->load_record('User');
Example 6 $this->load_record('User', 'field: name,lastname');
== is_numeric($value) ==
Checks if $value is numeric. This method is useful for user input validation.
Example
<?php class TestController extends ApplicationController { function add(){ $price = $this->request("price"); if($this->is_numeric($price)==false){ Flash::error(“Ivalid price input”); return; } /* ..*/ } } ?>