运行环境: winxp+apache2.055+php5.1.1+mysql5
下载cake_php
解压
目录结构为
/cake/
/app
/cake
/vendors
/index.php
/.htaccess
设置apache的httpd.conf
1.将网站根目录指向app下的webroot
DocumentRoot "E:/web/cake/app/webroot"
2.加载重写功能
LoadModule rewrite_module modules/mod_rewrite.so
3.AllowOverride一定要设成all
<Directory "E:/web/cake/app/webroot">
Options FollowSymLinks
AllowOverride ALL
</Directory>
4.修改database.php(由database.php.defalt另存一份得到)
class DATABASE_CONFIG
{
var $default = array('driver' => 'mysql',
'connect' =>
'mysql_connect',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'blog',
'prefix' => '');
var $test = array('driver' => 'mysql',
'connect' => 'mysql_connect',
'host' => 'localhost',
'login' => 'root',
'password' => '',
'database' => 'blog-test',
'prefix' => '');
)
$test这个可以不要
5.修改 /app/config/core.php
把define('AUTO_SESSION', true);
改为
define('AUTO_SESSION', false);
否则要出现sessions错误
6.实例程序
1).建表
CREATE TABLE players (
id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(50) NOT NULL,
position VARCHAR(25) NOT NULL,
team_id SMALLINT(6)
)
CREATE TABLE teams (
id SMALLINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
}
2).控制器(controller)
/app/controllers/players_controller.php
<?php
class PlayersController extends AppController
{
var $scaffold;
}
?>
/app/controllers/teams_controller.php
<?php
class TeamsController extends AppController
{
var $scaffold;
}
?>
3).模型(model)
/app/models/player.php
<?php
class Player extends AppModel
{
var $name = 'Player';
var $belongsTo = array('Team' =>
array('className' => 'Team',
'conditions' => '',
'order' => '',
'foreignKey' => 'team_id'
)
);
}
?>
/app/models/team.php
<?php
class Team extends AppModel
{
var $name = 'Team';
var $displayField = 'name';
}
?>
运行:
http://localhost/cake/teams
可以添加,修改,删除,列表
这个利用了scaffolds,没有自己写视图.可以去掉$scaffold,控制器的方法和视图都要自己写了
另外还有一点不爽,视图文件的扩展名都是thtml,不能用dw可视编辑,不过可以把cake\libs\controller\controller.php里的 var $ext='.thtml'改成html就可以直接用html视图文件了
此外,在生成的html页面里,总是有cakephp的标志(上面有大大的标题CakePHP Rapid Development
,下面还有一个cakephp的图标),虽然是cakephp的东西,但放到自己的项目中看起来总是不顺眼,要去掉
的话就修改
cake\libs\view\templates\layouts\default.thtml,这个是视图文件的通用模板框架(带头部和脚部) |