Solution to errors reported by smartyconfig_load and user-defined functions

Source: Internet
Author: User
The error temp. tplHTMLcode {config_loadfile = & quot ;.. /configs/. conf & quot; }{# s #}. confHTMLcodes = 'Test test' smarty config_load and user-defined function error
Temp. tpl
HTML code
  {config_load file="../configs/a.conf"}{#s#}

A. conf
HTML code
  S = 'Test test'

Error
Fatal error: Uncaught exception 'smartyexception' with message 'Unable to read config file '.. /configs/. 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 \ release. file. temp. tpl. php (36): Smarty_Internal_Config-> loadConfigVars (NULL, 'local') #5 C: \ wamp \ www \ smarty \ libs \ sysplugins \ smarty_internal_templatebase.php (180 ): struct (Object (Smarty_Internal_Template) #6 C: \ w in C: \ wamp \ www \ smarty \ libs \ sysplugins \ smarty_internal_resource_file.php on line 68


Custom functions
PHP code
  
  Register_function ("doloop", "myfun"); $ smarty-> display ("temp. tpl");?>


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


Error
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. php (62): Smarty-> register_function ('doloop ', 'myfun') #2 {main} thrown in C: \ wamp \ www \ smarty \ libs \ sysplugins \ smarty_internal_templatebase.php on line 806

I downloaded the smarty 3.1.8 unzip smarty-stable.zip] Feb 20th, 2012 files from the Smarty official website.
The stable word is stable. I just decompress this package and copy the libs folder to my www/smarty directory,
Other statements like running {$ smarty. server. SERVER_ADDR} in the temp. tpl template can be displayed normally. Why can't I just run config_load and UDF above?


------ Solution --------------------
Google, it turned out to be like this.
3.0 was previously implemented using register_function, and now the new method registerPlugin is used.
$ Smarty-> registerPlugin ("function", "demo", "demotest"); // specifies the type, which is called by a function. specify the template function name and php function name.
Function demotest ($ params ){
Extract ($ params); // get parameters a and B
Echo $ a. $ B; // output
}

Template syntax:
{Demo a = "2" B = "test "}
Output: 2 test

However, an error still occurs when {config_load} is used in the template. how can this problem be solved?
------ Solution --------------------
Ah, the config_load error is fixed.
I wrote {config_load file = "a. conf"} directly in the temp. tpl template "}
Create the configs folder in the temp. tpl file and put a. conf in the folder,
Strangely, I didn't specify a. conf in the configs folder. How did I find it?
This is because {config_load file = "../configs/a. conf"} should be written in temp. tpl.
What's going on?
How did smarty3.0 find it?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.