smarty-php / smarty

Smarty is a template engine for PHP, facilitating the separation of presentation (HTML/CSS) from application logic.
Other
2.24k stars 705 forks source link

Simple smarty function for use in template, has class_exist error? #885

Closed atlowl closed 1 year ago

atlowl commented 1 year ago

Having trouble following the very simple example for creating a function to use in my template. I'm hoping in the end to just be able to use this as a means to get data for a menu.

I've butchered the example a little but this is only to get it working. I created a function.load_ticker.php file in the plugins directory (even did a getPluginsDir() to make sure it's the right path)

function smarty_function_load_ticker($params, $smarty)
{
  // assign template variable
  $smarty->assign('test', '123');
}

So then in my shortcuts.tpl file i have

{load_ticker} {$test}

Then i get lots of the following...

Array ( [0] => /var/www/html/my_app/vendor/smarty/smarty/libs/plugins/ ) #0 __my_app_autoload(Smarty_Internal_Compile_Load_Ticker) #1 spl_autoload_call(Smarty_Internal_Compile_Load_Ticker) #2 class_exists(Smarty_Internal_Compile_Load_Ticker) called at [/var/www/html/my_app/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php:770] #3 Smarty_Internal_TemplateCompilerBase->getTagCompiler(load_ticker) called at [/var/www/html/my_app/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php:747] #4 Smarty_Internal_TemplateCompilerBase->callTagCompiler(load_ticker, Array (), Array ()) called at [/var/www/html/my_app/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php:1486] #5 Smarty_Internal_TemplateCompilerBase->compileTag2(load_ticker, Array (), Array ()) called at [/var/www/html/my_app/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php:550] #6 Smarty_Internal_TemplateCompilerBase->compileTag(load_ticker, Array ()) called at [/var/www/html/my_app/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php:2104] #7 Smarty_Internal_Templateparser->yy_r12() called at [/var/www/html/my_app/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php:2777] #8 Smarty_Internal_Templateparser->yy_reduce(12) called at [/var/www/html/my_app/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templateparser.php:2872] #9 Smarty_Internal_Templateparser->doParse(3, ) called at [/var/www/html/my_app/vendor/smarty/smarty/libs/sysplugins/smarty_internal_smartytemplatecompiler.php:128] #10 Smarty_Internal_SmartyTemplateCompiler->doCompile( {include file="sidebar.tpl"} {load_ticker} {$test}

My smarty version is 4.3.0 and my php version is 7.2 (which i know is old, maybe that's the problem?)

Any pointers?

Thanks

wisskid commented 1 year ago

You have posted the stack trace, bur I dont see the actual exception message. Do you have that?

In the stacktrace, I notice "__my_app_autoload". Might that be part of the problem?

atlowl commented 1 year ago

No sorry wisskid, i'm not sure i can find it. The output is just a mess of variables eg..

{*} , 1) called at [/var/www/html/my_app/vendor/smarty/smarty/libs/sysplugins/smarty_internal_templatecompilerbase.php:466] #11 Smarty_Internal_TemplateCompilerBase->compileTemplateSource(Smarty_Internal_Template Object ([_objType] => 2,[smarty] => Smarty_my_app Object ([auto_literal] => 1,[error_unassigned] => ,[use_include_path] => ,[_templateDirNormalized] => 1,[_joined_template_dir] => /var/www/html/my_app/templates/,[_configDirNormalized] => ,[_joined_config_dir] => ,[default_template_handler_func] => ,[default_config_handler_func] => ,[default_plugin_handler_func] => ,[_compileDirNormalized] => 1,[_pluginsDirNormalized] => 1,[_cacheDirNormalized] => 1,[force_compile] => ,[use_sub_dirs] => ,[allow_ambiguous_resources] => ,[merge_compiled_includes] => ,[extends_recursion] => 1,[force_cache] => ,[left_delimiter] => {,[right_delimiter] => },[literals] => Array (),[security_class] => Smarty_Security,[security_policy] => ,[allow_php_templates] => ,[debugging] => ,[debugging_ctrl] => NONE,[smarty_debug_id] => SMARTY_DEBUG,[debug_tpl] => ,[error_reporting] => ,[config_overwrite] => 1,[config_booleanize] => 1,[config_read_hidden] => ,[compile_locking] => 1,[cache_locking] => ,[locking_timeout] => 10,[default_resource_type] => file,[caching_type] => file,[default_config_type] => file,[cache_modified_check] => ,[registered_plugins] => Array (),[registered_objects] => Array (),[registered_classes] => Array (),[registered_filters] => Array (),[registered_resources] => Array (),[registered_cache_resources] => Array (),[autoload_filters] => Array (),[default_modifiers] => Array (),[escape_html] => ,[start_time] => 1683150467.7142,[_current_file] => /var/www/html/my_app/templates/page_my_shortcuts.tpl,[_parserdebug] => ,[_objType] => 1,[_debug] => ,[template_dir] => Array ([0] => /var/www/html/my_app/templates/),[_processedTemplateDir] => Array ([0] => 1),[config_dir] => Array ([0] => /var/www/html/my_app/configs),[_processedConfigDir] => Array (),[compile_dir] => /var/www/html/my_app/templates_c/,[plugins_dir] => Array ([0] => /var/www/html/my_app/vendor/smarty/smarty/libs/plugins/,[1] => /var/www/html/my_app/plugins/),[cache_dir] => /var/www/html/my_app/cache/,[obsoleteProperties] => Array ([0] => resource_caching,[1] => template_resource_caching,[2] => direct_access_security,[3] => _dir_perms,[4] => _file_perms,[5] => plugin_search_order,[6] => inheritance_merge_compiled_includes,[7] => resource_cache_mode),[accessMap] => Array ([template_dir] => TemplateDir,[config_dir] => ConfigDir,[plugins_dir] => PluginsDir,[compile_dir] => CompileDir,[cache_dir] => CacheDir),[SmartyisMutingUndefinedOrNullWarnings] => ,[cache_id] => ,[compile_id] => ,[caching] => 0,[compile_check] => 1,[cache_lifetime] => 3600,[tplFunctions] => Array (),[_cache] => Array ([plugin_files] => Array (),[resource_handlers] => Array ([file] => Smarty_Internal_Resource_File Object ([uncompiled] => ,[recompiled] => ,[hasCompiledHandler] => ))),[template_class] => Smarty_Internal_Template,[tpl_vars] => Array ([app_name] => Smarty_Variable Object ([value] => my_app,[nocache] => ),[title] => Smarty_Variable Object ([value] => My shortcuts,[nocache] => ........

I've been trying to dumb it down my project a little to maybe narrow it down? but i don't think there's anything else to stop it working?

I'm not sure about the __my_app_autoload ? Is there something i should turn off / on? Thanks

atlowl commented 1 year ago

Ah - sorted it. There was an autoload.php file doing some funny stuff. Thanks for the pointer!