Diferencia entre revisiones de «English Manual KumbiaPHP Framework 1.0 Index»
(→Instalar Kumbia: Traduccion de titulares) |
|||
(No se muestran 2 ediciones intermedias del mismo usuario) | |||
Línea 29: | Línea 29: | ||
= GETTING STARTED WITH KUMBIA PHP FRAMEWORK = | = GETTING STARTED WITH KUMBIA PHP FRAMEWORK = | ||
− | == [[ | + | == [[English_Instalar_Kumbia|Installing Kumbia]] == |
− | #[[ | + | #[[English_Instalar_Kumbia#Requirements|Requirements]] |
− | #[[ | + | #[[English_Instalar_Kumbia#Download_Kumbia|Download Kumbia]] |
− | #[[ | + | #[[English_Instalar_Kumbia#Module_Configuration.28_apache.2C_php_y_bbdd_.29|Module Configuration (Apache, PHP y bbdd)]] |
− | ##[[ | + | ##[[English_Instalar_Kumbia#Configurando_Apache|Configurando Apache]] |
− | ###[[ | + | ###[[English_Instalar_Kumbia#.C2.BFPor_qu.C3.A9_es_importante_Mod-Rewrite.3F|¿Por qué es importante Mod-Rewrite?]] |
− | ##[[ | + | ##[[English_Instalar_Kumbia#Configuraci.C3.B3n_de_PHP|Configuración de PHP]] |
− | ###[[ | + | ###[[English_Instalar_Kumbia#.C2.BFPorque_Kumbia_utiliza_PHP5.3F|¿Porque Kumbia utiliza PHP5?]] |
− | ##[[ | + | ##[[English_Instalar_Kumbia#Configurando_BB.DD|Configurando BB.DD]] |
− | ###[[ | + | ###[[English_Instalar_Kumbia#Configuraci.C3.B3n_de_MySQL|Configuración de MySQL]] |
− | ###[[ | + | ###[[English_Instalar_Kumbia#Configurando_Oracle|Configurando Oracle]] |
− | #[[ | + | #[[English_Instalar_Kumbia#Configurar_XAMPP|Configurar XAMPP]] |
− | ##[[ | + | ##[[English_Instalar_Kumbia#Instalando_XAMPP_bajo_Windows|Instalando XAMPP bajo Windows]] |
− | ##[[ | + | ##[[English_Instalar_Kumbia#Instalando_XAMPP_bajo_GNU.2FLinux|Instalando XAMPP bajo GNU/Linux]] |
− | ##[[ | + | ##[[English_Instalar_Kumbia#IInstalando XAMPP bajo Debian/Ubuntu Linux|Instalando XAMPP bajo Debian/Ubuntu Linux]] |
− | #[[ | + | #[[English_Instalar_Kumbia#Configurar_Apache2Triad|Configurar Apache2Triad]] |
− | #[[ | + | #[[English_Instalar_Kumbia#Verificar la instalación de Kumbia|Verificar la instalación de Kumbia]] |
− | ##[[ | + | ##[[English_Instalar_Kumbia#Instalar Kumbia PHP en producción de forma segura| Instalar Kumbia PHP en producción de forma segura]] |
== [[Estructura_de_Kumbia|Kumbia Structure]] == | == [[Estructura_de_Kumbia|Kumbia Structure]] == | ||
Línea 250: | Línea 250: | ||
Shows a view belonging to the same controller. | Shows a view belonging to the same controller. | ||
− | ''' | + | '''Example:''' |
<?php | <?php | ||
class ProductsController extends ApplicationController { | class ProductsController extends ApplicationController { | ||
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 277: | Línea 277: | ||
== post($value) == | == post($value) == | ||
− | + | Object oriented access to $_POST[$value]. | |
== get($value) == | == get($value) == | ||
− | + | Object oriented access to $_GET[$value]. | |
− | |||
== request($value) == | == request($value) == | ||
− | + | Object oriented access to $_REQUEST[$value]. | |
− | |||
== render_partial($name) == | == render_partial($name) == | ||
− | + | Render the partial view belonging to the same controller. Example: | |
− | ''' | + | '''Example:''' |
− | <?php | + | <?php |
− | class | + | class ProductsController extends ApplicationController { |
function index(){ | function index(){ | ||
− | $this->render_partial(' | + | $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: | + | == 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: | + | 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) == | == 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( | + | $this->redirect("/products/query"); |
== cache_layout($minutes) == | == cache_layout($minutes) == | ||
− | + | Cache the view views/layout/ belonging to the controller for $minutes. | |
== not_found($controller, $action) === | == 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 | + | <?php |
− | class | + | class TestController extends ApplicationController { |
function index(){ | function index(){ | ||
− | $this->render_text(" | + | $this->render_text("This is the index"); |
} | } | ||
function not_found($controller, $action){ | function not_found($controller, $action){ | ||
− | Flash::error(" | + | Flash::error("I am sorry. The action $action is not defined, redirecting to index..."); |
return $this->route_to('action: 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_response($type)== | ||
− | + | Set the controlled generated answer type. | |
− | |||
− | |||
− | ''' | + | If $type is "view" then kumbiaPHP will |
− | <?php | + | output the view only without layout, template or any html header. This is useful |
− | class | + | to generate AJAX or PDF output. |
+ | |||
+ | Another $type value is "XML". | ||
+ | |||
+ | '''Example''' | ||
+ | <?php | ||
+ | class TestController extends ApplicationController { | ||
function accion_ajax(){ | function accion_ajax(){ | ||
− | $this->set_response( | + | $this->set_response("view"); |
} | } | ||
} | } | ||
− | ?> | + | ?> |
− | == is_alnum($ | + | == is_alnum($value) == |
− | + | Checks if $value is alphanumeric. Useful for user input validation. | |
− | |||
− | <?php | + | <?php |
− | class | + | class TestController extends ApplicationController { |
− | function | + | function add(){ |
− | $ | + | $price = $this->request("price"); |
− | if($this->is_alnum($ | + | if($this->is_alnum($price)==false){ |
− | Flash::error( | + | Flash::error("price has not a valid value"); |
return; | return; | ||
} | } | ||
Línea 374: | Línea 376: | ||
} | } | ||
} | } | ||
− | ?> | + | ?> |
+ | |||
+ | == 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 | |
− | string | + | ** 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 421: | Línea 426: | ||
} | } | ||
} | } | ||
− | ?> | + | ?> |
===[[Obtener valores desde el controller]] === | ===[[Obtener valores desde el controller]] === |
Revisión actual del 16:55 23 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[editar]
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[editar]
- 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[editar]
Installing Kumbia[editar]
- Requirements
- Download Kumbia
- Module Configuration (Apache, PHP y bbdd)
- Configurar XAMPP
- Configurar Apache2Triad
- Verificar la instalación de Kumbia
Kumbia Structure[editar]
Características avanzadas[editar]
- ¡Parámetros con Nombre!
- Obtener valores en una aplicación Kumbia
- Uso de Paquetes (Namespaces)
- Programación modular
Primera Aplicación en Kumbia[editar]
- 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[editar]
MODELOS[editar]
- 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[editar]
- 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[editar]
- 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[editar]
Convenciones para RDBMs[editar]
ACTIVE RECORD API[editar]
This is a reference of the methods in ActiveRecord class sorted in alphabetic order:
Consultas[editar]
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[editar]
Promedios, Máximo y Mínimo[editar]
Creación-Actualización-Borrado de Registros[editar]
Validación[editar]
- validates_presence_of
- validates_length_of
- validates_numericality_of
- validates_email_in
- validates_uniqueness_of
- validates_date_in
- validates_format_of
Transacciones[editar]
Otros Métodos[editar]
Callbacks ActiveRecord[editar]
- 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[editar]
- Introducción
- Pertenece (belongs_to)
- Tiene un (has_one)
- Tiene muchos (has_many)
- Tiene y pertenece a muchos (has_and_belongs_to_many)
Paginadores[editar]
APPLICATION CONTROLLER[editar]
Métodos de la Clase ApplicationController[editar]
This class has several useful methods to work with controllers.
ApplicationController Class Methods[editar]
This class has several useful methods to work with controllers.
render($view)[editar]
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)[editar]
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)[editar]
Object oriented access to $_POST[$value].
get($value)[editar]
Object oriented access to $_GET[$value].
request($value)[editar]
Object oriented access to $_REQUEST[$value].
render_partial($name)[editar]
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])[editar]
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)[editar]
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)[editar]
Cache the view views/layout/ belonging to the controller for $minutes.
not_found($controller, $action) =[editar]
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)[editar]
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)[editar]
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...)[editar]
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; } /* ..*/ } } ?>