smarty 模板无法貌似无法调用,页面直接显示变量 刚注册的,第一次发帖,听说这么大神多,麻烦帮各位好人路过 帮忙看下 为啥我的页面全部直接显示变量了,是我的smarty没起作用吗?还有图片 css样式啥的路径都对为啥就不显示捏,急急急!!!! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 这是globla.php文件的内容<?php//全局调用文件,只需调用这个就行include_once ('./config/config.php');include_once('./common/smarty/Smarty.class.php');include_once ('./common/mysql.class.php');include_once ('./common/action.class.php');include_once ('./common/page.class.php');//数据库 ip等操作//实例化数据库$db = new action($mydbhost, $mydbuser, $mydbpw, $mydbname, ALL_PS, $mydbcharset);mysql_query("set names 'utf8'");//显示中文为问号的时候先执行这个并将数据库改为utf8,只需在这个全局文件中实例化$db的后面执行就可以//********smarty**********$smarty = new smarty();$smarty->template_dir = $smarty_template_dir;//模板文件目录$smarty->compile_dir = $smarty_compile_dir;$smarty->config_dir = $smarty_config_dir;$smarty->cache_dir = $smarty_cache_dir;$smarty->caching = $smarty_caching;$smarty->left_delimiter = $smarty_delimiter[0];$smarty->right_delimiter= $smarty_delimiter[1];$smarty->assign("t_dir",$smarty_template_dir);?>这个是index.php文件<?php/** * Created by PhpStorm. * User: chen * Date: 2016/8/25 * Time: 16:36 */include_once('global.php');$smarty ->assign("t_dir",$smarty->template_dir);//引入图片和文件路径,将html中的都替换成t_dir$smarty ->display("index.htm");?>既然首页能够打开说明是可以用的,就是变量解析不出来 $smarty_delimiter 从哪里来的?内容是什么? 那个是这个config.php配置文件中用于界定符号的$mydbhost ="localhost";//主机名称$mydbuser ="root";//数据库用户名$mydbpw ="";//数据库用户密码$mydbname ="news_php100";//数据库名称$mydbcharest ="utf8";//mysql_query("set names 'utf8'");//显示中文为问号的时候先执行这个并将数据库改为utf8/*smarty配置*/$smarty_template_dir ='./templates/';//设置模板目录,不能使用$smarty -> template_dir因为template目录下是空的$smarty_compile_dir ='./templates_c/';//设置编译目录$smarty_cache_dir ='./cache/';//设置缓存目录$smarty_config_dir ='./config/';//设置配置目录$smarty_caching =false;//是否使用缓存$smarty_delimiter =explode("|","{ | }");//修改作用边界符号?> 看php中 只给smarty加了 t_dir 变量$smarty ->assign("t_dir",$smarty->template_dir); 页面中的 $sm_class 数组没有看到在哪里加载的。你在页面单独输出{$t_dir} 看有没有值 include_once('global.php');$smarty ->assign("t_dir",$smarty->template_dir);//引入图片和文件路径,将html中的都替换成t_dirprint_r ($t_dir);$sql="SELECT * FROM `p_newsclass` where f_id=0 order by id DESC";$query=$db->query($sql);while($row_class=$db->fetch_array($query)){ $sm_class[]=array("name"=>$row_class[name],"id"=>$row_class[id]);} 那个数组也是index.php这个页面的,我直接这样print_r输出$t_dir没有值呀 ,我输出这个都有的print_r($smarty->template_dir)得到Array ( [0] => E:\XAMPP\htdocs\PHPnews\templates\ ) 这样的话print_r ($t_dir);应该也是这种值吧; 求 php 代码的站内信 源代码 有关算法的一个问题..实在写不出来了 一个PHP解析XML类,不知道怎么用? php怎么把unicode转换成gb2312 怎么可以在服务器连接满员的时候提示“请稍后访问,访问过多” 菜鸟转学PHP,大家来交流下经验,up有分啊 好东西,与大家分享! 我想知道CSDN論壇中左邊的菜單是怎麼做的,最好有源代碼 LINUX下的PHP问题 请问大家,哪里申请php+mysql的空间比较好,比较实惠,比较快? xampp下使用xdebug调试问题,ide是phpstorm php上传文件时候保存到数据库中的只有路径没有文件名称
<?php
//全局调用文件,只需调用这个就行
include_once ('./config/config.php');
include_once('./common/smarty/Smarty.class.php');
include_once ('./common/mysql.class.php');
include_once ('./common/action.class.php');
include_once ('./common/page.class.php');//数据库 ip等操作//实例化数据库
$db = new action($mydbhost, $mydbuser, $mydbpw, $mydbname, ALL_PS, $mydbcharset);
mysql_query("set names 'utf8'");//显示中文为问号的时候先执行这个并将数据库改为utf8,只需在这个全局文件中实例化$db的后面执行就可以//********smarty**********
$smarty = new smarty();
$smarty->template_dir = $smarty_template_dir;//模板文件目录
$smarty->compile_dir = $smarty_compile_dir;
$smarty->config_dir = $smarty_config_dir;
$smarty->cache_dir = $smarty_cache_dir;
$smarty->caching = $smarty_caching;
$smarty->left_delimiter = $smarty_delimiter[0];
$smarty->right_delimiter= $smarty_delimiter[1];
$smarty->assign("t_dir",$smarty_template_dir);
?>
这个是index.php文件
<?php
/**
* Created by PhpStorm.
* User: chen
* Date: 2016/8/25
* Time: 16:36
*/
include_once('global.php');
$smarty ->assign("t_dir",$smarty->template_dir);//引入图片和文件路径,将html中的都替换成t_dir
$smarty ->display("index.htm");
?>
既然首页能够打开说明是可以用的,就是变量解析不出来
$mydbhost ="localhost";//主机名称
$mydbuser ="root";//数据库用户名
$mydbpw ="";//数据库用户密码
$mydbname ="news_php100";//数据库名称
$mydbcharest ="utf8";
//mysql_query("set names 'utf8'");//显示中文为问号的时候先执行这个并将数据库改为utf8
/*smarty配置*/
$smarty_template_dir ='./templates/';//设置模板目录,不能使用$smarty -> template_dir因为template目录下是空的
$smarty_compile_dir ='./templates_c/';//设置编译目录
$smarty_cache_dir ='./cache/';//设置缓存目录
$smarty_config_dir ='./config/';//设置配置目录
$smarty_caching =false;//是否使用缓存
$smarty_delimiter =explode("|","{ | }");//修改作用边界符号?>
你在页面单独输出
{$t_dir} 看有没有值
$smarty ->assign("t_dir",$smarty->template_dir);//引入图片和文件路径,将html中的都替换成t_dir
print_r ($t_dir);
$sql="SELECT * FROM `p_newsclass` where f_id=0 order by id DESC";
$query=$db->query($sql);
while($row_class=$db->fetch_array($query)){
$sm_class[]=array("name"=>$row_class[name],"id"=>$row_class[id]);
} 那个数组也是index.php这个页面的,我直接这样print_r输出$t_dir没有值呀 ,我输出这个都有的print_r($smarty->template_dir)得到Array ( [0] => E:\XAMPP\htdocs\PHPnews\templates\ ) 这样的话print_r ($t_dir);应该也是这种值吧;