1、项目配置
编辑D:\xampp\htdocs\myapp\Conf\config.php,加入以下内容:
<?php
return array(
'APP_DEBUG'=>TRUE,
'DB_TYPE'=>'mysql',
'DB_HOST'=>'localhost',
'DB_NAME'=>'lk',
'DB_USER'=>'root',
'DB_PWD'=>'',
'DB_PORT'=>'3306',
'DB_PREFIX'=>'think_',
);
?>
这就是本项目myapp的配置文件,可见接下来就准备连接数据库了,比起第一课要实用一些。
2、定义业务操作
定义业务操作即是向控制器中添加相应的方法。
还是编辑D:\xampp\htdocs\myapp\Lib\Action下的IndexAction.class.php:
<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action{
public function index(){
$example = new Model('example');
echo '以下是数据库中的内容
';
$result = $example->select();
//以下两句用于调用模板输出
$this->assign('result',$result);
$this->display();
}
public function sendin(){
$example = new Model('example');
$example->Create();
$result = $example->add();
$this->redirect('index');
}
}
?>
index和sendin都要实现某些功能,sendin是向数据库中写入数据,然后返回index.php页面,index则将数据库中内容调用模板输出。
3、编写模板
模板就是我们能看到的html页面,是最后呈现在眼前的东西。
进入D:\xampp\htdocs\myapp\Tpl\default,在这底下先创建文件夹,和方法对应,如Index方法就需要有个Index文件夹,这个文件夹里存放Index方法中display的模板,模板是html文件。
建立Index/index.html:
这是五岳之巅自学的练习项目
姓名:
性别:
数据库中已有记录:
姓名:{$vo.name}
性别:{$vo.gender}