CakePHP框架首頁: http://www.cakephp.org/
下載後導入工程中,目錄結構如下圖(使用版本:1.1.19.6305)
搭建PHP環境,這裡使用了AppServ2.5.9。 下載主頁 http://www.appservnetwork.com/
MySQL中新建數據庫blog,並運行如下SQL文建表。
/**//* First, create our posts table: */
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
代碼:
<?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
);
}
?>