攻克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文建表。
/**//* 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());
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
);
}
?>
require_once ('cake/app_model.php');
class Post extends AppModel {
public $name = 'Post';
public $validate = array(
'title' => VALID_NOT_EMPTY,
'body' => VALID_NOT_EMPTY
);
}
?>
12下一页阅读全文
相关推荐
nicelife 2020-06-27
lxpandsq 2013-11-26
会写code的凳子哥 2012-07-01
nidaodiyaozama 2010-10-14
liujihaozhy 2009-12-01
0lzqth 2009-09-16
phptyong 2017-02-24
wangtengphp 2019-04-10
onlyquan 2019-04-09
wwwsurfphpseocom 2007-03-15
rootmiss 2009-02-01
PHP100 2019-03-27
PHP100 2019-03-27
编程10000问 2019-03-27
编程10000问 2019-03-27