搜索
系统检测到您的用户名不符合规范:

我想用smarty,但总是提示找不到文件,只好在smarty中加个tp常量了。

浏览:876 发布日期:2016年06月09日 分类:技术分享 关键字: smarty
我用了tp3.2.3+smarty,但tp自带的smarty提示模板文件找不到,

就下载了最新的smarty引擎,(目前的版本是smarty3.1.29),但还是提示模板文件找不到,但提示错误的文件变化了,变成了smarty引擎下面的sysplugins/smarty_internal_template.php文件,

错误提示:

:(
Unable to load template file 'Index/index.html'
错误位置

FILE: D:\www\!work4\thinkphp323full_smarty\ThinkPHP\Library\Vendor\Smarty\sysplugins\smarty_internal_template.php LINE: 139


最后在这个文件的第110行左右,把:

$this->template_resource = $template_resource;

修改为:

$this->template_resource = $template_resource; //原来的赋值语句
//加上THEME_PATH,可以啦,2016年06月09日
$this->template_resource = THEME_PATH.$template_resource;

这样就可以在thinkphp3.2.3中使用smarty了。

但是,有没有缺陷,还不知道,有没有更好的办法,也还不知道。

另外:

我的config配置如下:

<?php
return array(
'MODULE_ALLOW_LIST' => array('Admin', 'Home'),//设置只能访问的模块
'DEFAULT_MODULE' => 'Home', //默认访问模块,可以不出现在URL
'APP_USE_NAMESPACE' => true, //应用类库是否使用命名空间 3.2.1新增
'URL_CASE_INSENSITIVE' =>false, //区分大小写
'URL_MODEL' => 2, //使用rewrite模式

'DEFAULT_THEME' => 'default', //默认模板目录
'TMPL_DETECT_THEME_' => true, //自动侦测模板主题


'TMPL_ENGINE_TYPE' => 'Smarty',
'TMPL_ENGINE_CONFIG' => array(
'caching'=>true,
'template_dir' => TMPL_PATH,
'compile_dir' => CACHE_PATH,
'cache_dir' => TEMP_PATH,
'left_delimiter' => '{',
'right_delimiter' => '}',
),
);



.htaccess文件如下:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond 1ドル !^(DATA|images|otherThings)
##RewriteRule ^(.*)$ index.php/1ドル [QSA,PT,L]

RewriteRule ^(.*)$ index.php?s=1ドル [QSA,PT,L]
</IfModule>



App/Home/IndexController.class.php文件如下:
<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends Controller {
public function index(){
//$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 } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>ThinkPHP</b>!</p><br/>版本 V{$Think.version}</div><script type="text/javascript" src="http://ad.topthink.com/Public/static/client.js"></script><thinkad id="ad_55e75dfae343f5a1"></thinkad><script type="text/javascript" src="http://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script>','utf-8');

$a = 'abc';
$this->assign('a', $a);
$arr = array('php', 'javascript', 'css', 'html', 'smarty', 'thinkphp');
$this->assign('arr', $arr);

$this->display();

}
}



模板文件:
App/Home/View/default/Index/index.html

内容如下:

<!doctype html>
<html>
<head>
<meta charset="utf-8" />
</head>
<body>
<p>
使用了。变量a: {$a}
</p>
<p>
使用smarty的foreach
<ul>
{foreach from=$arr item=list}
<li>{$list}</li>
{/foreach}
</ul>
</p>
</body>
</html>





原文地址:http://qp500.cn/groupby/Blog/16686

附件 1.jpg ( 185.6 KB 下载:1 次 )

最佳答案
评论() 相关
后面还有条评论,
评论支持使用[code][/code]标签添加代码
您需要登录后才可以评论 登录 | 立即注册
收藏
50030
积分:1129 等级:LV3
热点推荐
(追記) (追記ここまで)
最新更新

我们

合作

网站

信息

ThinkPHP 是一个免费开源的,快速、简单的面向对象的 轻量级PHP开发框架 ,创立于2006年初,遵循Apache2开源协议发布,是为了敏捷WEB应用开发和简化企业应用开发而诞生的。ThinkPHP从诞生以来一直秉承简洁实用的设计原则,在保持出色的性能和至简的代码的同时,也注重易用性。并且拥有众多的原创功能和特性,在社区团队的积极参与下,在易用性、扩展性和性能方面不断优化和改进,已经成长为国内最领先和最具影响力的WEB应用开发框架,众多的典型案例确保可以稳定用于商业以及门户级的开发。

AltStyle によって変換されたページ (->オリジナル) /