Thinkphp学习笔记
Thinkphp学习笔记
一、入口index.php
<?php require './ThinkPHP/ThinkPHP.php' ; ?>二、配置Conf/config.php
<?php return array ( //'配置项' => '配置值' 'DB_TYPE' => 'mysql' , //使用的数据库类型 'DB_HOST' => 'localhost' , 'DB_NAME' => '' , //数据库名 'DB_USER' => '' , //访问数据库账号 'DB_PWD' => '' , //访问数据库密码 'DB_PORT' => '3306' , 'DB_PREFIX' => '' , //表前缀 'APP_DEBUG' => true, //调试模式开关 'TOKEN_ON' => true, //是否开启令牌验证 'URL_MODEL' => 1, //URL模式:0普通模式 1PATHINFO 2REWRITE 3兼容模式 //'SHOW_PAGE_TRACE'=> true, //'APP_DEBUG'=>true, 'DB_FIELD_CACHE' =>false, 'HTML_CACHE_ON' =>false, ); ?>三、模板使用
结构图
├─Down │ index.html │ ├─Game │ index.html │ ├─Index │ index.html │ ├─LineGame │ index.html │ ├─Public │ footer.html │ top.html │ └─Video index.html1、根目录Public文件夹
__PUBLIC__
网址
__ROOT__
2、引用公用的模板文件
<include file="Public:top" />引用的是Tpl\Public\top.html
<include file="Public:footer"/>
四、系统文件
1、Lib\Action\IndexAction.class.php
执行的是模板Tpl\Index\index.html
遵循的原则是在哪个函数里执行就用哪个函数对应的模板
<?php // 本类由系统自动生成,仅供测试用途 class IndexAction extends Action { public function index(){ //listvideo $video = M( 'video' ); // 实例化模型类 $re = $video ->where( "id>=1 && id<=10" )->select(); //查找 $this ->assign( 'listvideo' , $re ); //listdown $down = M( 'down' ); // 实例化模型类 $re = $down ->select(); $this ->assign( 'listdown' , $re ); //lm $lm = M( 'lm' ); // 实例化模型类 $re = $lm ->where( "id>=1&&id<=10" )->select(); //查找 $this ->assign( 'listlm' , $re ); //listjc $jc = M( 'jc' ); // 实例化模型类 $re = $jc ->where( "id>=1&&id<=10" )->select(); //查找 $this ->assign( 'listjc' , $re ); //display $this ->display(); } }列表及分页
<?php // 本类由系统自动生成,仅供测试用途 class VideoAction extends Action { public function index(){ //listvideo $video = M( 'video' ); // 实例化模型类 import( "ORG.Util.Page" ); //导入分页类 $count = $video -> count (); //计算总数 $p = new Page( $count , 10); $list = $video ->limit( $p ->firstRow . ',' . $p ->listRows)->order( 'id desc' )->select(); //$p->firstRow 当前页开始记录的下标,$p->listRows 每页显示记录数 $p ->setConfig( 'header' , '条数据' ); $p ->setConfig( 'prev' , "\<IMG src=\"__PUBLIC__\/image\/lt.gif\" align=absMiddle\>" ); $p ->setConfig( 'next' , "\<IMG src=\"__PUBLIC__\/image\/gt.gif\" align=absMiddle\>" ); $p ->setConfig( 'first' , '<<' ); $p ->setConfig( 'last' , '>>' ); $page = $p ->show(); //分页的导航条的输出变量 $this ->assign( "page" , $page ); $this ->assign( "listvideo" , $list ); //数据循环变量 $this ->assign( 'count' , $count ); //lm $lm = M( 'lm' ); // 实例化模型类 $re = $lm ->where( "id>=1&&id<=10" )->select(); $this ->assign( 'listlm' , $re ); //listjc $jc = M( 'jc' ); // 实例化模型类 $re = $jc ->where( "id>=1&&id<=10" )->select(); $this ->assign( 'listjc' , $re ); //display $this ->display(); } }查看更多关于Thinkphp学习笔记 - Thinkphp的详细内容...
声明:本文来自网络,不代表【好得很程序员自学网】立场,转载请注明出处:http://www.haodehen.cn/did6398