cakephp开发之脚手架(scaffold)

本文介绍了一种通过设置$scaffold变量快速创建应用程序的方法。仅需定义model与controller即可实现应用的基本功能,大大提升了开发效率。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

脚手架似乎是个偷懒的捷径,但是,在你急切的想要知道一个application的实际效果时,这个时候,它的作用就显示出来了,它的确很快!

创建脚手架所需要的全部只不过是一个model+controller,只要在控制器中设置了$scaffold变量,基本上就搞定了:)...

[b]mysql code:[/b]
CREATE TABLE IF NOT EXISTS `blogs` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
`user_id` int(11) NOT NULL,
`blogclass_id` mediumint(8) NOT NULL,
`title` varchar(255) NOT NULL,
`description` text NOT NULL,
`tag` varchar(255) NOT NULL,
`status` varchar(20) NOT NULL,
`post_password` varchar(20) DEFAULT NULL,
`view_count` mediumint(8) NOT NULL DEFAULT '0',
`created` datetime NOT NULL,
`modified` datetime NOT NULL,
PRIMARY KEY (`id`),
KEY `modified` (`modified`,`blogclass_id`,`created`),
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ;



[b]controller code:[/b]


<?php
/**
*
* @filesource
* @copyright Copyright 2009-2010, Inc.
* @package app
* @subpackage app.controllers
* @version $Revision: 1.1 $
* @author JangJushi
* @lastmodified $2010-7-20$
*/
class BlogsController extends AppController {

var $scaffold;
//to do ...

}
?>


[b]model code:[/b]



/**
* Blog 模型类
*
* 商户博客(日志)模型类,主要用于 blogs table 操作
*/
class Blog extends AppModel {

/**
* 模型名:Blog
*
* @var string
* @access public
*/
var $name = 'Blog';

/**
* 使用的数据表:blogs
*
* @var string
* @access public
*/
var $useTable = 'blogs';

//to do ...

}
?>


ok,现在,你在浏览器输入:http://localhost:900/blogs/(我配置了virtual machine) 试试看看吧~~~
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值