首頁 後端開發 php教程 继承smarty类时遇到的有关问题,求指导!

继承smarty类时遇到的有关问题,求指导!

Jun 13, 2016 pm 01:26 PM
gt php quot smarty this

继承smarty类时遇到的问题,求指导!!
我直接把smarty的libs目录拷进测试项目中,测试项目很简单,有两个文件demo.php和init.inc.php,然后我在init.inc.php做一些配置,比如界定符、模板目录之类,如果是以这种方式:

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php include_once './libs/Smarty.class.php';
    $tpl=new Smarty;
    $tpl->left_delimiter="<!--{";
    $tpl->right_delimiter="}-->";
?&gt;

登入後複製
配置完成后在demo.php中我这样写
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php require_once 'init.inc.php';
        $title="this is a title";
    $content="this is my content";
    $tpl->assign("title",$title);
    $tpl-&gt;assign("content",$content);
    $tpl-&gt;display("default/test.tpl");
?&gt;

登入後複製
显示没问题
如果是另外做一个继承与smarty类的类mySmarty代码如下,在init.inc.php中
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
       <?php include_once './libs/Smarty.class.php';
    class mySmarty extends Smarty{
        function mySmarty(){
            $this->Smarty();
            $this-&gt;template_dir="./templates/";
            $this-&gt;compile_dir="./templates_c/";
            $this-&gt;config_dir="./configs/";
            $this-&gt;cache_dir="./cache/";
            $this-&gt;caching=true;
            $this-&gt;left_delimiter="<!--{";
            $this->right_delimiter="}-->";
            $this-&gt;assign('app_name','mySmartyTest');
        }
    }
       ?&gt;

登入後複製

在demo.php中我做如下的调用和显示
PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
<?php require_once 'init.inc.php';
    $tpl=new mySmarty;
    $title="this is a title";
    $content="this is my content";
    $tpl->assign("title",$title);
    $tpl-&gt;assign("content",$content);
    $tpl-&gt;display("default/test.tpl");
?&gt;

登入後複製
则会报500错误,到底怎么回事呢,求高手指导,谢谢!!

------解决方案--------------------
你把 php 的错误显示功能打开,就知道哪里有问题了

继承的
如果是 Smarty 2 应该无大错
如果是 Smarty 3 那就是另一回事了
------解决方案--------------------
俺打工六年,就一个经验告诉你,尽早放弃 smarty 这种没人性的模版引擎。
------解决方案--------------------
因为那东西麻烦死了
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章

倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章

倉庫:如何復興隊友
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前 By 尊渡假赌尊渡假赌尊渡假赌

熱門文章標籤

記事本++7.3.1

記事本++7.3.1

好用且免費的程式碼編輯器

SublimeText3漢化版

SublimeText3漢化版

中文版,非常好用

禪工作室 13.0.1

禪工作室 13.0.1

強大的PHP整合開發環境

Dreamweaver CS6

Dreamweaver CS6

視覺化網頁開發工具

SublimeText3 Mac版

SublimeText3 Mac版

神級程式碼編輯軟體(SublimeText3)

適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南 Dec 24, 2024 pm 04:42 PM

適用於 Ubuntu 和 Debian 的 PHP 8.4 安裝和升級指南

CakePHP 日期和時間 CakePHP 日期和時間 Sep 10, 2024 pm 05:27 PM

CakePHP 日期和時間

CakePHP 檔案上傳 CakePHP 檔案上傳 Sep 10, 2024 pm 05:27 PM

CakePHP 檔案上傳

CakePHP 專案配置 CakePHP 專案配置 Sep 10, 2024 pm 05:25 PM

CakePHP 專案配置

CakePHP 路由 CakePHP 路由 Sep 10, 2024 pm 05:25 PM

CakePHP 路由

討論 CakePHP 討論 CakePHP Sep 10, 2024 pm 05:28 PM

討論 CakePHP

CakePHP 快速指南 CakePHP 快速指南 Sep 10, 2024 pm 05:27 PM

CakePHP 快速指南

如何設定 Visual Studio Code (VS Code) 進行 PHP 開發 如何設定 Visual Studio Code (VS Code) 進行 PHP 開發 Dec 20, 2024 am 11:31 AM

如何設定 Visual Studio Code (VS Code) 進行 PHP 開發

See all articles