Domanda

Everyone!

I'm working with PHP and Smarty in my project. I'm using namespaces and I'm having a problem when I call Smarty functions, for sample cycle

I'm having this error: Syntax Error in template ".\sys\adm\template\fields\inputFileField.tpl" on line 23 "{cycle values="um,dois"}" unknown tag "cycle"

I'm using spl_autoload_register to auto load classes in project:

function smartyAutoloader($className) {
    $file = "sys/classes/smarty/$className.class.php";

    if (file_exists($file)) {
        require $file;
        return true;
    }

    return false;
}

I did not change the namespace in Smarty class, so I'm importing Smarty this way:

use \Smarty;

If I comment the cycle code, my code works correctly.

Follow is the problemmatic code:

{for $x = 0 to 10}
    {cycle values="um,dois"} {*line 23 on inputFileField.tpl*}
{/for}

I'm not knowing to use namespace and Smarty in same project. I'm sure this error is because of namespaces. Can someone help me?

Thanks in advance

È stato utile?

Soluzione 2

I found this post at the Smarty forum

The problem seems to be a wrong or relative path to the plugin folder. After setting the path to the plugin folder absolut, it works fine, even with namespaces.

Have also a look at the Smarty documentation:

Technical Note

For best performance, do not setup your $plugins_dir to have to use the PHP include path. Use an absolute pathname, or a path relative to SMARTY_DIR or the current working directory.

Altri suggerimenti

You have to set setPluginsDir like this:

$dirSep = DIRECTORY_SEPARATOR;
$path = dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR;
$smarty->setPluginsDir($path."smarty".$dirSep."libs".$dirSep."plugins");
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top