smarty-php / smarty

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

{$smarty.cookies.username} in 5.0.0 rc2 #931

Open markocrni opened 6 months ago

markocrni commented 6 months ago

Smarty 5.0.0 rc2, php 8.2.13 In template : {$smarty.cookies.username} or {$smarty.request.page}

Throws error: 'Call to undefined function Smarty\Compile\smarty_strtolower_ascii()', in file '/Smarty/Compile/SpecialVariableCompiler.php', at line 45

wisskid commented 6 months ago

Well, the PHP docs state: "For functions and constants, PHP will fall back to global functions or constants if a namespaced function or constant does not exist." and the units indicatie this works perfectly. Somehow, it seems you have not loaded the 'functions.php' file, even though it is defined in composer.json autoload.files.

markocrni commented 6 months ago

Thanks for your reply. Acutaly I don't use composer, because it's not an option for the project I'm working. I think it would be good if you post instructions on how to include Smarty without composer, because I believe there are more cases like mine. My code for autoregistring and loading Smarty

AutoLoader::register(function ($sClassName) {
    if($sClassName === 'Smarty') {
        include( FWK_DIR . 'lib_tp/Smarty/Smarty.php');
        include( FWK_DIR . 'lib_tp/Smarty/functions.php');
        return;
    }
    $aParts = explode('\\', $sClassName);
    if((isset($aParts[0]) && $aParts[0] === 'Smarty')) {
        include( FWK_DIR . 'lib_tp/' . str_replace('\\', '/', $sClassName) . '.php');
    }
});

I'll do a little more research here...

wisskid commented 6 months ago

can you explain why using composer is not an option?

markocrni commented 5 months ago

The whole problem was that functions.php was not loaded. I still think it would be nice if you post instructions on how to include Smarty without composer.

wisskid commented 5 months ago

But you cannot explain why using composer is not an option?