You are on page 1of 5

Cookbook 1.

3 Aplicaciones de Consola Principales


2.x Book | 1.2 Book | 1.1 Book
Generacin de Cdigo con Bake
Ya has aprendido sobre scaffolding en CakePHP: una forma simple de armar una
aplicacin con slo una base de datos y algunas clases bsicas. La consola Bake es
otro esfuerzo para tener CakePHP corriendo rpido. La consola Bake puede crear
cualquiera de los ingredientes bsicos de CakePHP: modelos, vistas y controladores. Y
no estamos hablando slo de clases estructurales: Bake puede crear una aplicacin
completamente funcional en slo unos minutos. De hecho, Bake es el paso natural que
toman las aplicaciones una vez que han pasado por la etapa de scaffolding
Para utilizar Bake necesitar ejecutar el script localizado en el directorio /cake/console/
Dependiendo de tu configuracin, podras necesitar darle permisos de ejecucin al script
bash o llamarlo usando./cake bake. La consola de Cake corre usando PHP CLI
(command line interface). Si tienes algn problema con el script, asegrate de que tienes
PHP CLI instalado y que adems tienes los mdulos necesarios habilitados(Ej: MySQL).
Cuando utilices Bake por primera vez, te pedir que crees un archivo de configuracin
para la base de datos, si todava no creaste uno.
Una vez que hayas configurado la base de datos, cuando ejecutes Bake te presentar
estas opciones:
Alternativamente, puedes ejecutar cualquiera de estos comandos directamente de la lnea
de comandos:
El manual
Comenzando con
CakePP
Principios b!sicos de
CakePP
"esarrollando con
CakePP
#areas comunes con
CakePP
Componen$es del
%&cleo
Core Be'a(iors
)Compor$amien$os
Basicos*
A+udan$es del Core
,ibrerias de u$ilidades
del n&cleo
Aplicaciones de
Consola Principales
Generacin de
Cdigo con Bake
Ges$in del Es-uema
de la BB"" +
.igraciones
.odi/icando el
#., producido por
de/ec$o del scrip$
bake
"eplo+men$
E0emplo de Aplicacin
Apendices
Page
con$en$s
Generacin de Cdigo
con Bake
Bake impro(emen$s
in 1.3

B&s-ueda
CakePHP Downloads Documentation Community Services
Generacin de Cdigo con Bake documentacin de CakePHP Cook... http://book.cakephp.org/1.3/es/The-Manual/Core-Console-Application...
1 de 5 27/07/2014 12:36
Bake impro(emen$s in 1.3
For 1.3 bake has had a significant overhaul, and a number of features and enhancements
have been built in.
Two new tasks (FixtureTask and TestTask) are accessible from the main bake menu
A third task (TemplateTask) has been added for use in your shells.
All the different bake tasks now allow you to use connections other than default for
baking. Using the -connection parameter.
Plugin support has been greatly improved. You can use either -plugin PluginName or
Plugin.class.
Questions have been clarified, and made easier to understand.
Multiple validations on models has been added.
Self Associated models using parent_id are now detected. For example if your model
is named Thread, a ParentThread and ChildThread association will be created.
Fixtures and Tests can be baked separately.
Baked Tests include as many fixtures as they know about, including plugin detection
(plugin detection does not work on PHP4).
So with the laundry list of features, well take some time to look at some of the new
commands, new parameters and updated features.
New FixtureTask, TestTask and TemplateTask.
Fixture and test baking were a bit of a pain in the past. You could only generate tests
when baking the classes, and fixtures could only be generated when baking models. This
made adding tests to your applications later or even regenerating fixtures with new
schemas a bit painful. For 1.3 weve separated out Fixture and Test making them
separate tasks. This allows you to re-run them and regenerate tests and fixtures at any
point in your development process.
In addition to being rebuildable at any time, baked tests are now attempt to find as many
fixtures as possible. In the past getting into testing often involved fighting through
numerous Missing Table errors. With more advanced fixture detection we hope to make
testing easier and more accessible.
Test cases also generate skeleton test methods for every non-inherited public method in
your classes. Saving you one extra step.
TemplateTask is a behind the scenes task, and it handles file generation from templates. In
previous versions of CakePHP baked views were template based, but all other code was
not. With 1.3 almost all the content in the files generated by bake are controlled by
templates and the TemplateTask.
The FixtureTask not only generates fixtures with dummy data, but using the interactive
Generacin de Cdigo con Bake documentacin de CakePHP Cook... http://book.cakephp.org/1.3/es/The-Manual/Core-Console-Application...
2 de 5 27/07/2014 12:36
1ndice | siguien$e | an$erior
options or the -records option you can enable fixture generation using live data.
New bake command
New commands have been added to make baking easier and faster. Controller, Model,
View baking all feature an all subcommand, that builds everything at once and makes
speedy rebuilds easy.
Would bake all the models for an application in one shot. Similarly cake bake controller
all would bake all controllers and cake bake view all would generate all view files.
Parameters on the ControllerTask have changed as well. cake bake controller scaffold
is now cake bake controller public. ViewTask has had an -admin flag added, using
-admin will allow you to bake views for actions that begin with outing.admin
As mentioned before cake bake fixture and cake bake test are new, and have several
subcommands each. cake bake fixture all will regenerate all the basic fixtures for your
application. The -count parameter allows you to set the number of fake records that are
created. By running fixture task interactively you can generate fixtures using the data in
your live tables. You can use cake bake test !t"pe# !class# to create test cases for
already created objects in your app. Type should be one of the standard CakePHP types
(component, controller, model, helper, behavior) but doesnt have to be. Class
should be an existing object of the chosen type.
Templates Galore
New in bake for 1.3 is the addition of more templates. In 1.2 baked views used templates
that could be changed to modify the view files bake generated. In 1.3 templates are used
to generate all output from bake. There are separate templates for controllers, controller
action sets, fixtures, models, test cases, and the view files from 1.2. As well as more
templates, you can also have multiple template sets or, bake themes. Bake themes can be
provided in your app, or as part of plugins. An example plugin path for bake theme would
be app$plugins$bake_t%eme$vendors$s%ells$templates$dark_red$. An app bake theme
called blue_bunn" would be placed in app$vendors$s%ells$templates$blue_bunn". You can
look at cake$console$templates$default$ to see what directories and files are required of
a bake theme. However, like view files, if your bake theme doesnt implement a template,
other installed themes will be checked until the correct template is found.
Additional plugin support.
New in 1.3 are additional ways to specify plugin names when using bake. In addition to
cake bake plugin Todo controller Posts, there are two new forms. cake bake controller
Todo.Posts and cake bake controller Posts -plugin Todo. The plugin parameter can be
while using interactive bake as well. cake bake controller -plugin Todo, for example will
allow you to use interactive bake to add controllers to your Todo plugin. Additional /
multiple plugin paths are supported as well. In the past bake required your plugin to be in
app/plugins. In 1.3 bake will find which of the pluginPaths the named plugin is located on,
and add the files there.
Generacin de Cdigo con Bake documentacin de CakePHP Cook... http://book.cakephp.org/1.3/es/The-Manual/Core-Console-Application...
3 de 5 27/07/2014 12:36
2ound an issue3 4ubmi$ a correc$ion on gi$'ub
5 documen$a$ion on 'o6 $o con$ribu$e 7
en | p$ | es | 0a | |
/r
Generacin de Cdigo con Bake documentacin de CakePHP Cook... http://book.cakephp.org/1.3/es/The-Manual/Core-Console-Application...
4 de 5 27/07/2014 12:36
Copyright 2012, Cake Software Foundation, Inc. Creado con Sphinx 1.2.
Generacin de Cdigo con Bake documentacin de CakePHP Cook... http://book.cakephp.org/1.3/es/The-Manual/Core-Console-Application...
5 de 5 27/07/2014 12:36

You might also like