继承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="}-->"; ?>
登入後複製
- 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->assign("content",$content); $tpl->display("default/test.tpl"); ?>
登入後複製
如果是另外做一个继承与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->template_dir="./templates/"; $this->compile_dir="./templates_c/"; $this->config_dir="./configs/"; $this->cache_dir="./cache/"; $this->caching=true; $this->left_delimiter="<!--{"; $this->right_delimiter="}-->"; $this->assign('app_name','mySmartyTest'); } } ?>
登入後複製
在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->assign("content",$content); $tpl->display("default/test.tpl"); ?>
登入後複製
------解决方案--------------------
你把 php 的错误显示功能打开,就知道哪里有问题了
继承的
如果是 Smarty 2 应该无大错
如果是 Smarty 3 那就是另一回事了
------解决方案--------------------
俺打工六年,就一个经验告诉你,尽早放弃 smarty 这种没人性的模版引擎。
------解决方案--------------------
因为那东西麻烦死了
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn

熱門文章
擊敗分裂小說需要多長時間?
3 週前
By DDD
倉庫:如何復興隊友
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前
By 尊渡假赌尊渡假赌尊渡假赌
公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗?
3 週前
By 王林

熱門文章
擊敗分裂小說需要多長時間?
3 週前
By DDD
倉庫:如何復興隊友
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island冒險:如何獲得巨型種子
3 週前
By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.能量晶體解釋及其做什麼(黃色晶體)
1 週前
By 尊渡假赌尊渡假赌尊渡假赌
公眾號網頁更新緩存難題:如何避免版本更新後舊緩存影響用戶體驗?
3 週前
By 王林

熱門文章標籤

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

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

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

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