drdyszuy488152 2014-01-03 19:53
浏览 72
已采纳

Smarty - 捕获“无法加载模板”错误

i use automatic loading .tpl files by get parameter.

The parameter might be wrong and on next move it stops by error "Smarty: Unable to load template".

Can i catch this error and redirect page to some default template?

Thank you very much!

$seo = $params[0];
$smarty->display($seo . '.tpl');
  • 写回答

1条回答 默认 最新

  • doudi1449 2014-01-03 20:16
    关注

    Smarty has a function to check if a template exists.

    From the documentation:

    if( !$smarty->template_exists($mid_template) ){
        $mid_template = 'page_not_found.tpl';
    }
    

    You can for example use it like this:

    if($smarty->template_exists($template)) {
        header("Location: error.html");
        exit();
    }
    $smarty->display($template);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统