|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
jaze22 Smarty Rookie
Joined: 06 Jan 2010 Posts: 6
|
Posted: Thu Jan 09, 2020 10:30 am Post subject: Smarty 3.1.34 Undefined index: user |
|
|
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 |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Fri Jan 10, 2020 6:48 am Post subject: |
|
|
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 |
|
|
|
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
|