攻克CakePHP(PHP中的Ruby On Rails框架)图文介绍第1/2页
CakePHP框架首页: http://www.cakephp.org/
下载后导入工程中,目录结构如下图(使用版本:1.1.19.6305)
搭建PHP环境,这里使用了AppServ2.5.9。 下载主页 http://www.appservnetwork.com/
MySQL中新建数据库blog,并运行如下SQL文建表。
CREATE TABLE posts (
id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(50),
body TEXT,
created DATETIME DEFAULT NULL,
modified DATETIME DEFAULT NULL
);
/**//* Then insert some posts for testing: */
INSERT INTO posts (title,body,created)
VALUES ('The title', 'This is the post body.', NOW());
INSERT INTO posts (title,body,created)
VALUES ('A title once again', 'And the post body follows.', NOW());
INSERT INTO posts (title,body,created)
VALUES ('Title strikes back', 'This is really exciting! Not.', NOW());
修改工程app/config/目录下database.php.default文件名为database.php,并修改其配置。
修改Apache的httpd.conf文件。
Apache2.2版本的,直接把#LoadModule rewrite_modulemodules/mod_rewrite.so的注释删掉即可。
2.0以前的版本,据说要修改2个地方: LoadModule rewrite_module libexec/httpd/mod_rewrite.so 和AddModule mod_rewrite.c
增加Model:
/app/models/post.php
代码:
require_once ('cake/app_model.php');
class Post extends AppModel {
public $name = 'Post';
public $validate = array(
'title' => VALID_NOT_EMPTY,
'body' => VALID_NOT_EMPTY
);
}
?>