Академический Документы
Профессиональный Документы
Культура Документы
$ cd ./cake/console/
$ cake bake
Depending on the configuration of your setup, you may have to set execute rights
on the cake bash script or call it using ./cake bake. The cake console is run u
sing the PHP CLI (command line interface). If you have problems running the scri
pt, ensure that you have the PHP CLI installed and that it has the proper module
s enabled (eg: MySQL).
When running Bake for the first time, you ll be prompted to create a Database Co
nfiguration file, if you haven t created one already.
After you ve created a Database Configuration file, running Bake will present yo
u with the following options:
--------------------------------------------------------------App : app
Path: /path-to/project/app
--------------------------------------------------------------Interactive Bake Shell
--------------------------------------------------------------[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[Q]uit
What would you like to Bake? (D/M/V/C/P/Q)
>
Alternatively, you can run any of these commands directly from the command line:
$ cake bake db_config
$ cake bake model
$ cake bake view
O primeiro passo transferir a pasta cake de dentro da basta do domnio para o seu ro
ot. A estrutura de diretrios fica assim com esta mudana:
/
/cake
/eberfdias.com
/app
/webroot
index.php
/etc...
Depois disto, basta configurar o arquivo index.php na sua pasta webroot, dentro
da pasta app [se este mesmo o nome que voc deu]. A nica linha que voc modifica esta
:
define( CAKE_CORE_INCLUDE_PATH , ROOT);
trocando por:
define( CAKE_CORE_INCLUDE_PATH , dirname(dirname(dirname(dirname(__FILE__)))));
O comando dirname pega o diretrio do arquivo em questo, mesmo se ele for um arquiv
o incluso, ou seja, ele pega a pasta do arquivo incluido, no do arquivo que o est
incluindo. Sendo assim, ns retornamos 4 nveis para encontrarmos a pasta cake. Uma fe
z feito isso, o seu aplicativo dever funcionar normalmente acessando o core do ca
ke fora da pasta do domnio!
Se voc usa windows pra desenvover seus sites [como eu], voc tambm pode mover a past
a cake pra fora da pasta do seu aplicativo com essas configuraes. Assim, se voc des
envolve varios sites com Cake, voc pode manter apenas um core pra todos eles. A a
tualizao do core tmb se torna mais simples desta forma!
O mais legal que o CakePHP deixa voc customizar o local de todos os pedaos do seu ap
licativo, possibilitando o aumento da segurana de seu cdigo longe do alcance dos u
surios. Para saber mais sobre isso s dar uma olhadinha neste captulo do manual do C
akePHP.
Fonte: http://www.eberfdias.com/blog/2008/01/17/cakephp-apenas-um-core-para-dive
rsos-aplicativos/
Usando o Scaffold
CakePHP: Using scaffolding for rapid application building
ScaffoldingThats right, Im still on my CakePHP journey. Ive been spending quite a b
it of time now trying to match what I want to build with how to go about doing i
t in CakePHP. We all know that the blog example is pretty simplistic - a real wo
rld app wont be quite so straightforward. At the moment, Im trying to build up an
intranet of sorts, with lots of different independant apps, and its driving me cr
azy How would I structure the it? Should I use plugins? The folders, the views etc.
Yes, its all still a big mess.
In any case, I found that CakePHP has a really nifty feature that really helps w
ith sorting out the mess, and its called scaffolding.
Scaffolding is Cakes way of quickly building up a basic application that can Creat
e, Retrieve, Update and Delete (or CRUD) objects, with just a few simple lines of code
All we need to do is to setup your database table, the model and the controller,
and thats it - you can browse your database, add new entries, delete, update etc
<?php
class Author extends AppModel
{
var $name = Author ;
}
?>
<?php
adronizadas com botes add, delete e edit, formulrios padres de edio e views padroniza
das para inspeo de itens no banco de dados.
Para adicionar scaffold na sua aplicao, em seu controller adicione a varivel $scaff
old:
<?php
class CategoriasController extends AppController {
var $scaffold;
}
?>
Assumindo que voc criou at mesmo o arquivo de classe model Categoria (em /app/mode
ls/categoria.php), voc est pronto para ir. Visite http://exemplo.com/categorias pa
ra ver seu novo scaffold.
Nota: criar mtodos em controllers que tem scaffold pode causar resultados no desej
ados. Por exemplo, se voc criar uma mtodo index() em um controller com scaffold, s
eu mtodo index ser renderizado ao invs da funcionalidade do scaffold.
O scaffold est ciente das associaes entre models, ento se o seu model Categoria est a
ssociado atravs de belongsTo a um model Usuario, voc ver a listagem de IDs do Usuar
io. Se voc ao invs do ID quer ver outra coisa (como o nome do usurio), voc pode conf
igurar a varivel $displayField no model.
Vamos configurar a varivel $displayField na class Usuario para que as categorias
mostrem usurios pelo nome ao invs de apenas o ID no scaffold. Esse recurso faz com
que o scaffold se torne mais legvel em muitas situaes.
<?php
class Usuario extends AppModel {
var $name = Usuario ;
var $displayField = nome ;
}
?>
Personalizando os scaffolds
Se voc est procurando por algo um pouco diferente em suas views de scaffold, voc po
de criar templates. Ns no recomendamos essa tcnica para aplicaes em nvel de produo, m
esse nvel de personalizao pode ser til durante as fases de interao.
A personalizao feita atravs da criao de templates para as views:
Views scaffold personalizadas para um controller
especfico (PostsController neste exemplo) deve ser colocado assim:
/app/views/posts/scaffold.index.ctp
/app/views/posts/scaffold.show.ctp
/app/views/posts/scaffold.edit.ctp
/app/views/posts/scaffold.new.ctp
Views scaffold para todos os controllers devem ser colocadas assim:
/app/views/scaffolds/index.ctp
/app/views/scaffolds/show.ctp
/app/views/scaffolds/edit.ctp
/app/views/scaffolds/new.ctp
/app/views/scaffolds/add.ctp
3.11 Scaffolding
* Edit
* Comments (2)
* History
Application scaffolding is a technique that allows a developer to define and cre
ate a basic application that can create, retrieve, update and delete objects. Sc
affolding in CakePHP also allows developers to define how objects are related to
each other, and to create and break those links.
All thats needed to create a scaffold is a model and its controller. Once you set
the $scaffold variable in the controller, youre up and running.
CakePHPs scaffolding is pretty cool. It allows you to get a basic CRUD applicatio
n up and going in minutes. So cool that you ll want to use it in production apps
. Now, we think its cool too, but please realize that scaffolding is... well...
just scaffolding. It s a loose structure you throw up real quick during the begi
nning of a project in order to get started. It isn t meant to be completely flex
ible, its meant as a temporary way to get up and going. If you find yourself real
ly wanting to customize your logic and your views, its time to pull your scaffol
ding down in order to write some code. CakePHPs Bake console, covered in the next
section, is a great next step: it generates all the code that would produce the
same result as the most current scaffold.
Scaffolding is a great way of getting the early parts of developing a web applic
ation started. Early database schemas are subject to change, which is perfectly
normal in the early part of the design process. This has a downside: a web devel
oper hates creating forms that never will see real use. To reduce the strain on
the developer, scaffolding has been included in CakePHP. Scaffolding analyzes yo
ur database tables and creates standard lists with add, delete and edit buttons,
standard forms for editing and standard views for inspecting a single item in t
he database.
To add scaffolding to your application, in the controller, add the $scaffold var
iable:
<?php
class CategoriesController extends AppController {
var $scaffold;
}
?>
1.
2.
3.
4.
5.
<?php
class CategoriesController extends AppController {
var $scaffold;
}
?>
Assuming youve created even the most basic Category model class file (in /app/mod
els/category.php), youre ready to go. Visit http://example.com/categories to see
your new scaffold.
Creating methods in controllers that are scaffolded can cause unwanted results.
For example, if you create an index() method in a scaffolded controller, your in
dex method will be rendered rather than the scaffolding functionality.
Scaffolding is knowledgeable about model associations, so if your Category model
belongsTo a User, youll see related User IDs in the Category listings. If youd ra
ther see something besides an ID (like the users first name), you can set the $di
splayField variable in the model.
Lets set the $displayField variable in our User class so that users related to ca
tegories will be shown by first name rather than just an ID in scaffolding. This
feature makes scaffolding more readable in many instances.
<?php
class User extends AppModel {
var $name = User ;
var $displayField = first_name ;
}
?>
<?php
class User extends AppModel {
var $name = User ;
var $displayField = first_name ;
}
?>
1.
2.
3.
4.
5.
6.
Available Shells:
app/vendors/shells/:
- none
vendors/shells/:
- none
cake/console/libs/:
acl
api
bake
console
extract
A instalao das tradues muito simples. Faa o download do arquivo que contm as mensagen
em portugus neste link, e descompacte-o no diretrio app/locale.
$ tar -xzvf pt_br.tar.gz -C <CAMINHO AT SUA APLICAO>/app/locale
Aps a extrao, edite o arquivo core.php localizado no diretrio config da sua aplicao, e
insira a seguinte linha:
<?php
Configure::write( Config.language , pt-br );
?>