刚注册的,第一次发帖,听说这么大神多,麻烦帮各位好人路过 帮忙看下 为啥我的页面全部直接显示变量了,是我的smarty没起作用吗?还有图片 css样式啥的路径都对为啥就不显示捏,急急急!!!!

解决方案 »

  1.   

    这是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");
    ?>
    既然首页能够打开说明是可以用的,就是变量解析不出来
      

  2.   

    $smarty_delimiter 从哪里来的?内容是什么?
      

  3.   

    那个是这个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("|","{ | }");//修改作用边界符号?>
      

  4.   

    看php中 只给smarty加了 t_dir 变量$smarty ->assign("t_dir",$smarty->template_dir); 页面中的 $sm_class 数组没有看到在哪里加载的。
    你在页面单独输出
    {$t_dir} 看有没有值
      

  5.   

    include_once('global.php');
    $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);应该也是这种值吧;