cakephp在windows下的配置方法,cakephp学习实例2008年01月22日 星期二 15:31运行环境: 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
可以添加,修改,删除,列表 |