thinkphp 实现模板文件在一个目录下
2022-08-03 09:57:03
102
{{single.collect_count}}

thinkphp 实现模板在同一个目录下

thinkphp 默认模板目录结构是

|-Tpl

|----模块名

|--------操作名.html

|--------操作名.html

|----模块名

|--------操作名.html

|--------操作名.html

现在如果想实现这样的结构:

|-Tpl

|----模块名_操作名.html|----模块名_操作名.html|----模块名_操作名.html|----模块名_操作名.html

笨方法是这么写的

$this->display('./Tpl/模块名_操作名.html');如果碰上项目分组,还得加上项目路径,实在是麻烦。

其实有一种办法,不需要自己写路径即可实现。

示例:

我们先创建一个公共的模块CommonAction.class.php 代码如下:

if(!defined("ACCESS"))exit('Access Denied!');//猜一猜有什么用

class CommonAction extends Action {

//自定义一个_display()方法

function _display(){

parent::display(APP_PATH.'Tpl/'.MODULE_NAME.'_'.ACTION_NAME.'.html');

}

}

然后,其他模块都继承这个CommonAction

define("ACCESS",TRUE);//猜猜有什么作用

class IndexAction extends CommonAction {

function index(){

$this->_display();

}

}

在项目下的Tpl目录中新建 Index_index.html ,然后访问首页,得到满意的结果!

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}