Im currently using codeigniter 2 with ci-Smarty. Just been trying to add a smarty output filter but not having much luck. Its as if the function cannot be found or something?
I am using a plugin as the output filter function and have the following code:
LOCATION: /libraries/Smarty.php
// Set email output filter
$this->loadFilter('output', 'protect_email');
LOCATION: /third_party/Smarty/plugins/function.protect_email.php
function smarty_function_protect_email($tpl_output, Smarty_Internal_Template $template)
{
$tpl_output =
preg_replace('!(\S+)@([a-zA-Z0-9\.\-]+\.([a-zA-Z]{2,3}|[0-9]{1,3}))!',
'$1%40$2', $tpl_output);
return $tpl_output;
}
The above seems to throw the following smarty error:
Fatal error: Uncaught exception ‘SmartyException’ with message
‘outputfilter “protect_email” not callable’ in
/home/something/public_html/application/third_party/Smarty/sysplugins/smarty_internal_templatebase.php:717
Stack trace: #0
/home/something/public_html/application/libraries/Smarty.php(46):
Smarty_Internal_TemplateBase->loadFilter(‘output’, ‘protect_email’) #1
/home/something/public_html/system/core/Loader.php(1095):
CI_Smarty->__construct(Array) #2
/home/something/public_html/system/core/Loader.php(975):
CI_Loader->_ci_init_class(‘Smarty’, ”, NULL, NULL) #3
/home/something/public_html/system/core/Loader.php(216):
CI_Loader->_ci_load_class(‘smarty’, NULL, NULL) #4
/home/something/public_html/application/libraries/MY_Parser.php(29):
CI_Loader->library(‘smarty’) #5
/home/something/public_html/system/core/Loader.php(1099):
MY_Parser->__construct() #6
/home/something/public_html/system/core/Loader.php(938):
CI_Loader->_ci_init_class(‘Parser’, ‘MY_’, NULL, NULL) #7
/home/something/public_html/system/core/Loader.php(216): CI_Loa in
/home/something/public_html/application/third_party/Smarty/sysplugins/smarty_internal_templatebase.php
on line 717
Sorry about it being so long! Just thought seeing the whole error may help.
Thanks a lot for reading and hope someone can help.
–>EDIT
Also just tried to explicitly set the plugins directory location using:
$this->setPluginsDir(config_item('plugin_directory'));
The echoed out the location which is correct but still get the same problem 🙁
Okay that was a silly mistake.
For anyone else who has the same problem I was just looking through and realised the plugin should not be referred to as a regular function. For example it should have been called:
Also make the same amends with the function name as well so in my case it should be called:
This worked great for me.