java多线程    Java入门    vsftp    ftp    linux配置    centos    FRP教程    HBase    Html5缓存    webp    zabbix    分布式    neo4j图数据库    

thinkphp深入学习小笔记2

前期背景条件

项目根目录为
http://localhost/site/
新建的模块叫home

我们在IndexController.php里有个add函数

public function add(){
        //$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>!</p><br/>[ 您现在访问的是Home模块的Index控制器 ]</div><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');
		echo U('Index/add');
		$this->display('index');
 
    }

访问路径为

http://localhost/site/home/Index/add

1.问题:输出URL如何为静态

U('Index/add');
默认值为
/site/index.php/Home/Index/add.html

 'URL_MODEL'          => '1', //URL模式

返回
/site/index.php/Home/Index/add.html

 'URL_MODEL'          => '2', //URL模式

返回
/site/Home/Index/add.html

 'URL_MODEL'          => '3', //URL模式

返回
/site/index.php?s=/Home/Index/add.html

2.问题:如何缩短路径

总文件index.php

增加
define('BIND_MODULE', 'Home');

这样整个路径修改为
http://localhost/site/Index/add

URL_MODEL 为2的情况 add返回路径修改为

/site/Index/add.html

3.问题:如何让U方法出来的路径都是小写
必要条件
// 开启调试模式 建议开发阶段开启 部署阶段注释或者设为false
define('APP_DEBUG',false);

必要条件2
config.php

 'URL_CASE_INSENSITIVE'  =>  true,

模板调路径 {:U('Index/Add')}

4.循环模板
Controller层

	$m = M('Web');
		$result = $m->select();
		$this->assign('list',$result);
		$this->display('index');

View层

<foreach name="list" item="v" >
    {$key}|{$v.name}
</foreach>

5.模板找公共文件
__PUBLIC__

输出/site/Public

6. 错误,正确模板提示 config.php

'TMPL_ACTION_SUCCESS'  =>  'Index:success',  //home/Home/View/Index/success.html
 
'TMPL_ACTION_ERROR'  =>  'Index:success',

原来的跳转模板文件路径

ThinkPHP\Tpl\


This entry was posted in PHP and tagged , , . Bookmark the permalink.
月小升QQ 2651044202, 技术交流QQ群 178491360
首发地址:月小升博客https://java-er.com/blog/thinkphp-study/
无特殊说明,文章均为月小升原创,欢迎转载,转载请注明本文地址,谢谢
您的评论是我写作的动力.

196 Responses to thinkphp深入学习小笔记2

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*