cake php官網:http://cakephp.org/
使用bake生成代碼.
1:首先你要把數據庫建好,例如我們使用PowerDesigner把數據庫設計好,導出sql語句,在mysql中創建數據庫tfss,創建兩個簡單的表(特別需要注意表名以及外鍵的命名,請參考cakephp的命名規范):
drop table if exists admingroups;
/*==============================================================*/
/* Table: admingroups */
/*==============================================================*/
create table admingroups
(
id int not null auto_increment comment '管理組ID',
ac_user int not null default 1 comment '允許創建用戶(0: false ; 1: trure)',
ac_class int not null default 1 comment '允許創建班級組別(0: false ; 1: trure)',
primary key (id)
);
alter table admingroups comment '管理組表';
drop table if exists usergroups;
/*==============================================================*/
/* Table: usergroups */
/*==============================================================*/
create table usergroups
(
id int not null auto_increment comment '用戶組ID',
admingroup_id int not null default 0 comment '用戶組類型1:學生;2:校長;3:老師)',
group_name varchar(50) not null default '' comment '用戶組名稱(管理組為學生的:中1~中6總共6個級別)',
user_count int not null default 0 comment '用戶數量',
primary key (id)
);
alter table usergroups comment '用戶組表';
2: 首先要將php的php.exe加入環境變量中,例如我的php安裝在E:workServerPHPCore下,將該路徑加入到path中
3: 在命令行里面執行如下命令:php cakephp的bake文件路徑 bake
例如你的cakephp解壓文件全部放在
“E:/work/PHPPro/CakePHPTest/”目錄下
那么則在命令行執行: php E:/work/PHPPro/CakePHPTest/lib/Cake/Console/cake.php bake
1) 首先要知道相關命令:
[D]atabase Configuration
[M]odel
[V]iew
[C]ontroller
[P]roject
[F]ixture
[T]est case
[Q]uit
2):執行了以上命令,開始配置數據庫
Welcome to CakePHP v2.1.0 Console
---------------------------------------------------------------
App : app
Path: E:workPHPProCakePHPTestapp
---------------------------------------------------------------
Your database configuration was not found. Take a moment to create one.
---------------------------------------------------------------
---------------------------------------------------------------
Database Configuration:
---------------------------------------------------------------
Name:
[default] > default
Datasource:(Mysql/Postgres/Sqlite/Sqlserver)
[Mysql] > mysql
Persistent Connection? (y/n)
[n] > n
Database Host:
[localhost] > localhost
Port?
[n] > 3306
User:
[root] > root
Password:
> 000000
Database Name:
[cake] > tfss
Table Prefix?
[n] > n
Table encoding?
[n] > n
---------------------------------------------------------------
The following database configuration will be created:
---------------------------------------------------------------
Name: default
Driver: mysql
Persistent: false
Host: localhost
Port: 3306
User: root
Pass: ****
Database: tfss
---------------------------------------------------------------
Look okay? (y/n)
[y] > y
Do you wish to add another database configuration?
[n] > n
Creating file E:workPHPProCakePHPTestappConfigdatabase.php
Wrote 'E:workPHPProCakePHPTestappConfigdatabase.php'
3)使用bake all生成m,v,c
我們在命令行敲入: php E:/work/PHPPro/CakePHPTest/lib/Cake/Console/cake.php bake all
執行如下:
Welcome to CakePHP v2.1.0 Console
---------------------------------------------------------------
App : app
Path: E:workPHPProCakePHPTestapp
---------------------------------------------------------------
Bake All
---------------------------------------------------------------
Possible Models based on your current database:
1. Admingroup
2. Usergroup
Enter a number from the list above,
type in the name of another model, or 'q' to exit
[q] > 1
Baking model class for Admingroup...
Creating file E:workPHPProCakePHPTestappModelAdmingroup.php
Wrote `E:workPHPProCakePHPTestappModelAdmingroup.php`
PHPUnit is not installed. Do you want to bake unit test files anyway? (y/n)
[y] > n
Baking controller class for Admingroups...
Creating file E:workPHPProCakePHPTestappControllerAdmingroupsController.php
Wrote `E:workPHPProCakePHPTestappControllerAdmingroupsController.php`
PHPUnit is not installed. Do you want to bake unit test files anyway? (y/n)
[y] > n
Baking `index` view file...
Creating file E:workPHPProCakePHPTestappViewAdmingroupsindex.ctp
Wrote `E:workPHPProCakePHPTestappViewAdmingroupsindex.ctp`
Baking `view` view file...
Creating file E:workPHPProCakePHPTestappViewAdmingroupsview.ctp
Wrote `E:workPHPProCakePHPTestappViewAdmingroupsview.ctp`
Baking `add` view file...
Creating file E:workPHPProCakePHPTestappViewAdmingroupsadd.ctp
Wrote `E:workPHPProCakePHPTestappViewAdmingroupsadd.ctp`
Baking `edit` view file...
Creating file E:workPHPProCakePHPTestappViewAdmingroupsedit.ctp
Wrote `E:workPHPProCakePHPTestappViewAdmingroupsedit.ctp`
Bake All complete
4)關于.ctp模板文件
如果使用zend studio是無法打開.ctp文件的,那么我就增加后綴名吧
window -> Preferences -> General -> Content Types -> PHP Content type 添加*.ctp后綴
添加文件關聯
window -> Preferences -> General -> Editor -> File Associations 添加關聯
下一篇 Symfony安裝配置失敗