很多
文档 就算是
官方 也 官味十足 不愿意用最简单的话来表达流程
下面通过 简单的代码 来讲述 FleaPHP
框架是如何工作的 以及流程。(我们正在编写草根文档 希望您的参与:
http://www.woyuw.cn)
例子:网站的栏目功能(即网站的头部导航)
目录结构
cms
- Controller 控制层
文件夹
- Model 模型层文件夹
- View 视图层文件夹
- Config 配置文件夹
- css 网站样式表文件夹
- js 网站JS文件夹
- templates_c
- images
数据库
创建数据库 new_cms
CREATE TABLE `new_class` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(255) collate utf8_bin NOT NULL,
`wtime` int(11) NOT NULL,
PRIMARY KEY (`id`)
)
INSERT INTO `new_class` (`id`, `title`, `wtime`) VALUES
(1, 0x504850, 424234234),
(2, 0x414a4158, 4234234);
首先 /index.php 程序的入口
<?php
/*
应用程序路口
*/
define('APP',dirname(__FILE__).'/APP/');
/*
@ FLEA 框架文件
*/
require_once ('../LIBS/FLEA/FLEA.php'); //我是将FLEA放在上级目录 这样容易实现正站共享FLEA
/*
@ 视图文件夹
*/
define('VIEW_DIR',APP.'View/');
/*
@ 配置文件夹
*/
define('Config',APP.'Config/');
/*
@ 数据库配置
*/
$dsnConfigFile=Config.'DSN_config.php';
/*
@
Smarty 模板配置
*/
$smartyConfigFile=Config.'/SMARTY_config.php';
define('WEB_ROOT','http://localhost/cms/');
define('WEB_IMG',WEB_ROOT.'APP/images/');
define('WEB_CSS',WEB_ROOT.'APP/css/');
define('WEB_JS',WEB_ROOT.'APP/js/');
register_app_inf($dsnConfigFile);
register_app_inf($smartyConfigFile);
//set_app_inf('dispatcher', 'FLEA_Dispatcher_Auth');
FLEA::import(dirname(__FILE__) . '/APP');
FLEA::init();
run();
?>
APP/Config/DSN_config.php 数据库配置
<?php
/*
数据库配置文件
*/
return array
(
'dbDSN'=>array
(
'driver' => 'mysql',
'host' => 'localhost',
'login' => 'root',
'password' => 'xxxxxx', //密码
'database' => 'new_cms' //数据库的名称
)
);
?>
APP/Config/SMARTY_config.php Smarty扩展
<?php
/*
smarty
*/
return array
(
'view' =>'FLEA_View_Smarty',
'viewConfig'=>array
(
'smartyDir' => APP.'smarty', //smarty解压到路径 请修改到您smat解压到路径
'template_dir' => APP . '/View',
'compile_dir' => APP.'/templates_c',
'cache_dir' => APP.'cache',
'caching' => false //我关闭的缓存
)
);
?>
APP/Controller/Default.php 默认控制层
<?php
/*
@ 程序默认入口
*/
class Controller_Default extends FLEA_Controller_Action
{
var $_MODEL_new_DB;
function Controller_Default()
{
/*
调用Smarty
*/
$this->smarty=& $this->_getView();
/*
频道表数据库模型
*/
$this->_MODEL_DB_channel=& get_singleton("MODEL_DBchannel");
}
function actionIndex()
{
/*
findALL 读取 【请查询findALL的使用方法】
*/
$value=$this->_MODEL_DB_channel->findALL(NULL,"id asc");
$this->smarty->assign('channel',$value);
$this->smarty->display('index.html');
}
}
?>
APP/Model/DBchannel.php 栏目数据模型层
<?php
/*
栏目数据模型层
*/
load_class('FLEA_Db_TableDataGateway');
class MODEL_DBchannel extends FLEA_Db_TableDataGateway
{
/*
数据库表名称
*/
var $tableName='new_class';
var $primaryKey='id';
}
?>
APP/View/index.html 视图
<!DOCTYPE
html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="{php}echo WEB_CSS;{/php}globals.css" />
</head>
<body>
<div class="main_w_800 b_bottom_1 main_h_1 main_center ">
<!--logo-->
<div class="logo_div">
<img src="{php}echo WEB_IMG.'logo.gif';{/php}">
</div>
<!--logoEND-->
<div>
<div style="height:80px;" class="main_b_1"> </div>
<div>
{section name=channel_key loop=$channel step=1}
{$channel[channel_key].title}
{/section}
</div>
</div>
</div>
</body>
</html>
APP/css/globals.css
/*
网页顶部间距
*/
body
{
margin-top:3px;
}
/*
@ 宽度为800
*/
.main_w_800
{
width:800px;
}
/*
@ 高度 100px
*/
.main_h_1
{
height:100px;
}
/*
@ 边框颜色为 1px #99999
*/
.main_b_1
{
border: 1px solid #999999;
}
.main_center
{
margin-left:auto;
margin-right:auto;
}
.b_top_0
{
border-top:0px;
}
.b_bottom_0
{
border-bottom: 0px;
}
.b_left_0
{
border-laft:0px;
}
.b_right_0
{
border-right:0px;
}
.b_top_1
{
border: 1px solid #999999;
}
.b_bottom_1
{
border-bottom: 1px solid #999999;
}
.b_left_1
{
border-left: 1px solid #999999;
}
.b_right_1
{
border-right: 1px solid #999999;
}
/*
@ LOGO 池
*/
.logo_div
{
height:90px;
float:left;
padding-top:5px;
}
[
本帖最后由 itw1 于 2007-12-18 23:24 编辑 ]