php框架

 首页 > php框架 > ThinkPHP > Thinkphp学习笔记 - Thinkphp

Thinkphp学习笔记 - Thinkphp

分享到:
【字体:
导读:
          Thinkphp学习笔记一、入口index php?phprequire 39; ThinkPHP ThinkPHP php 39;;?二、配置Conf config php?phpreturnarray( 39;配...

Thinkphp学习笔记

Thinkphp学习笔记

一、入口index.php

  1. require './ThinkPHP/ThinkPHP.php'
  2. ?> 

二、配置Conf/config.php

  1. return array
  2. //'配置项'    => '配置值' 
  3. 'DB_TYPE'    => 'mysql',       //使用的数据库类型 
  4. 'DB_HOST'    => 'localhost'
  5. 'DB_NAME'    => '',       //数据库名 
  6. 'DB_USER'    => '',         //访问数据库账号 
  7. 'DB_PWD'     => '',//访问数据库密码 
  8. 'DB_PORT'    => '3306'
  9. 'DB_PREFIX'  => '',//表前缀 
  10. 'APP_DEBUG'  => true,//调试模式开关 
  11. 'TOKEN_ON'   => true,//是否开启令牌验证 
  12. 'URL_MODEL'  => 1,//URL模式:0普通模式 1PATHINFO 2REWRITE 3兼容模式 
  13. //'SHOW_PAGE_TRACE'=> true, 
  14. //'APP_DEBUG'=>true, 
  15. 'DB_FIELD_CACHE'=>false, 
  16. 'HTML_CACHE_ON'=>false, 
  17. ); 
  18. ?> 

三、模板使用

结构图

  1. ├─Down 
  2. │      index.html 
  3. │ 
  4. ├─Game 
  5. │      index.html 
  6. │ 
  7. ├─Index 
  8. │      index.html 
  9. │ 
  10. ├─LineGame 
  11. │      index.html 
  12. │ 
  13. ├─Public 
  14. │      footer.html 
  15. │      top.html 
  16. │ 
  17. └─Video 
  18.         index.html 

1、根目录Public文件夹

__PUBLIC__

网址

__ROOT__

2、引用公用的模板文件

引用的是TplPublictop.html

四、系统文件

1、LibActionIndexAction.class.php

执行的是模板TplIndexindex.html

遵循的原则是在哪个函数里执行就用哪个函数对应的模板

  1. // 本类由系统自动生成,仅供测试用途 
  2. class IndexAction extends Action { 
  3. public function index(){ 
  4. //listvideo 
  5. $video = M( 'video' ); // 实例化模型类 
  6. $re=$video->where("id>=1 && id<=10")->select();     //查找 
  7. $this->assign('listvideo',$re); 
  8. //listdown 
  9. $down = M( 'down' ); // 实例化模型类 
  10. $re=$down->select(); 
  11. $this->assign('listdown',$re); 
  12. //lm 
  13. $lm = M( 'lm' ); // 实例化模型类 
  14. $re=$lm->where("id>=1&&id<=10")->select();     //查找 
  15. $this->assign('listlm',$re); 
  16. //listjc 
  17. $jc = M( 'jc' ); // 实例化模型类 
  18. $re=$jc->where("id>=1&&id<=10")->select();     //查找 
  19. $this->assign('listjc',$re); 
  20. //display 
  21. $this->display(); 

列表及分页

  1. // 本类由系统自动生成,仅供测试用途 
  2. class VideoAction extends Action { 
  3. public function index(){ 
  4. //listvideo 
  5. $video = M( 'video' ); // 实例化模型类 
  6. import("ORG.Util.Page");//导入分页类 
  7. $count = $video->count();    //计算总数 
  8. $p = new Page($count, 10); 
  9. $list = $video->limit($p->firstRow . ',' . $p->listRows)->order('id desc')->select(); 
  10. //$p->firstRow 当前页开始记录的下标,$p->listRows 每页显示记录数 
  11. $p->setConfig('header''条数据'); 
  12. $p->setConfig('prev'""); 
  13. $p->setConfig('next'""); 
  14. $p->setConfig('first''<<'); 
  15. $p->setConfig('last''>>'); 
  16. $page = $p->show();            //分页的导航条的输出变量 
  17. $this->assign("page"$page); 
  18. $this->assign("listvideo"$list); //数据循环变量 
  19. $this->assign('count',$count); 
  20. //lm 
  21. $lm = M( 'lm' ); // 实例化模型类 
  22. $re=$lm->where("id>=1&&id<=10")->select(); 
  23. $this->assign('listlm',$re); 
  24. //listjc 
  25. $jc = M( 'jc' ); // 实例化模型类 
  26. $re=$jc->where("id>=1&&id<=10")->select(); 
  27. $this->assign('listjc',$re); 
  28. //display 
  29. $this->display(); 
分享到:
ThinkPHP 基本注意事项 - Thinkphp
ThinkPHP 基本注意事项 1. 缓存 修改模版后要及时删除缓存,否则不能生效。 2. 控制器 2.1 变量赋值 注意变量用的&#039;&#039;,而非$ $this->assign(&#039;str&#039;,"Hello ThinkPHP!"); 而不是: $this->assign($str,"Hello ThinkPHP!"); 2.2 模版路径 $this->display(&#039;def...
第一次用THINKPHP 报路径错 - Thinkphp
第一次用THINKPHP 报路径错 我第一次 看网上写的代码:   报告出错: Warning: require(../ThinkPHPCommon/runtime.php) [function.require]: failed to open stream: No such file or directory in D:\web\htdocs\ThinkPHP\ThinkPHP.php on line 36 Fatal error: require() [fun...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……