Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 3.1.34 Undefined index: user

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
jaze22
Smarty Rookie


Joined: 06 Jan 2010
Posts: 6

PostPosted: Thu Jan 09, 2020 10:30 am    Post subject: Smarty 3.1.34 Undefined index: user Reply with quote

I am using Smarty 3.1.34 and am seeing this:

Message: 'Undefined index: user'

Which is basically saying the variable user does not exist.

From googling it seems I should be able to disable this E_NOTICE in smarty by using this:

$smarty->error_reporting = E_ALL & ~E_NOTICE;

But it does not disable the notice! The only thing that get's rid of it is:

{if isset($user)}{$user}{/if}

Please help, what do I need to do to disable the Undefined index notice?

Here is my smarty config:

Code:
public static function renderTemplate($template, $args = [])
    {
        static $smarty = null;

        if ($smarty === null) {
            $smarty = new \Smarty();
            $smarty->setTemplateDir(getcwd() . '/App/smarty/templates/default');
            $smarty->setCompileDir(getcwd() . '/App/smarty/templates_c/');
            $smarty->setConfigDir(getcwd() . '/App/smarty/configs/');
            $smarty->setCacheDir(getcwd() . '/App/smarty/cache/');
            $smarty->debugging = true;
            // error_reporting hide E_NOTICE so don't see smarty undefined index variable, but it does not work
            $smarty->error_reporting = E_ALL & ~E_NOTICE;
            $smarty->setCompileCheck(true);
            $smarty->force_compile = true;
            $smarty->setCacheLifetime(1);
        }

        foreach ($args as $key => $value) {
            $smarty->assign($key, $value);
        }
        $smarty->display($template);
    }
Back to top
View user's profile Send private message
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Jan 10, 2020 6:48 am    Post subject: Reply with quote

Define variable "user" for your templates.
This is the only right way to do it.

PHP can be configured to forbid changing its settings from within the script, that's probably why you can't change them.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP