smarty config_load 和 自訂函數 報錯解決方案

來源:互聯網
上載者:User
smarty config_load 和 自訂函數 報錯
temp.tpl
HTML code
{config_load file="../configs/a.conf"}{#s#}

a.conf
HTML code
s='測試測試'

報錯
Fatal error: Uncaught exception 'SmartyException' with message 'Unable to read config file '../configs/a.conf'' in C:\wamp\www\smarty\libs\sysplugins\smarty_internal_resource_file.php:68 Stack trace: #0 C:\wamp\www\smarty\libs\sysplugins\smarty_config_source.php(86): Smarty_Internal_Resource_File->getContent(Object(Smarty_Config_Source)) #1 C:\wamp\www\smarty\libs\sysplugins\smarty_internal_config_file_compiler.php(81): Smarty_Config_Source->__get('content') #2 C:\wamp\www\smarty\libs\sysplugins\smarty_internal_config.php(189): Smarty_Internal_Config_File_Compiler->compileSource(Object(Smarty_Internal_Config)) #3 C:\wamp\www\smarty\libs\sysplugins\smarty_internal_config.php(214): Smarty_Internal_Config->compileConfigSource() #4 C:\wamp\www\smarty\templates_c\187938f6ec55068ed23f0f2de8d126b1ae3149c7.file.temp.tpl.php(36): Smarty_Internal_Config->loadConfigVars(NULL, 'local') #5 C:\wamp\www\smarty\libs\sysplugins\smarty_internal_templatebase.php(180): content_4fb7f6591b8ab2_26457252(Object(Smarty_Internal_Template)) #6 C:\w in C:\wamp\www\smarty\libs\sysplugins\smarty_internal_resource_file.php on line 68


自訂函數
PHP code
register_function("doloop","myfun");    $smarty->display("temp.tpl");?>


temp.tpl
HTML code
{doloop times="5"}


報錯
Fatal error: Uncaught exception 'SmartyException' with message 'Call of unknown method 'register_function'.' in C:\wamp\www\smarty\libs\sysplugins\smarty_internal_templatebase.php:806 Stack trace: #0 [internal function]: Smarty_Internal_TemplateBase->__call('register_functi...', Array) #1 C:\wamp\www\smarty\smarty.php(62): Smarty->register_function('doloop', 'myfun') #2 {main} thrown in C:\wamp\www\smarty\libs\sysplugins\smarty_internal_templatebase.php on line 806

我從smarty官方網站上下載了Smarty 3.1.8 [Smarty-stable.zip] Feb 20th, 2012檔案啊
stable這個單詞是穩定的意思 我就下了這個包 解壓後 我把裡面的libs檔案夾拷貝到我的www/smarty目錄下,
其它像在temp.tpl模板裡運行{$smarty.server.SERVER_ADDR}這個語句可以正常顯示啊,為什麼就運行上面的config_load和自訂函數就不行啊


------解決方案--------------------
google了一下,原來是這樣的啊。
3.0以前是用register_function來實現,現在的是新方法registerPlugin。
$smarty->registerPlugin(“function”,”demo”, “demotest”);;//制定類型,這裡制定是函數調用,指定模板函數名稱和php函數名稱
function demotest($params) {
extract($params);//擷取參數a與b了
echo $a.$b;//輸出
}

模板寫法:
{demo a=”2″ b=”test”}
輸出:2test

可是模板中使用{config_load}還是要出錯啊,怎麼解決?
------解決方案--------------------
啊,config_load出錯也解決了
我在temp.tpl模板中直接寫出{config_load file="a.conf"}
在temp.tpl檔案中建立了configs檔案夾,並把a.conf放在檔案夾裡面,
奇怪是的,我沒指定a.conf在configs檔案夾裡啊,它是怎麼找到的?
總因該在temp.tpl寫成{config_load file="../configs/a.conf"}這對啊,可這樣要報錯
怎麼回事?
smarty3.0是怎麼找到它的?
  • 聯繫我們

    該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

    如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.