我用了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 +FollowSymli
nks
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 次 )