View previous topic :: View next topic |
Author |
Message |
makamo66 Smarty Rookie
Joined: 21 Jun 2021 Posts: 5
|
Posted: Mon Jun 21, 2021 12:36 pm Post subject: There's something wrong with my if/else condition in index.p |
|
|
in index.php in the root directory I have:
Code: | if (isset($_REQUEST['form']) && !empty($_REQUEST['form']) ){
$form = $_REQUEST['form'];
$smarty->assign('form',$form);
}
if (isset($form)){
//assign a bunch of stuff using $form
}
else {
//display the template as the homepage
$smarty->display("templates/language/alphabet.tpl");
} |
When I view my home page at localhost, I get the following errors:
Notice: Undefined index: form in C:\xampp\htdocs\projectname\templates_c\ecc481657059b848b2528d61c69a8548ceaaab4b.file.alphabet.tpl.cache.php on line 351
Notice: Trying to get property 'value' of non-object in C:\xampp\htdocs\projectname\templates_c\ecc481657059b848b2528d61c69a8548ceaaab4b.file.alphabet.tpl.cache.php on line 351
This is line 351 in the cached file:
Code: | <?php }elseif($_smarty_tpl->tpl_vars['form']->value==3){?> |
It seems to be having a problem because there isn't a query parameter for the home page. The other pages look like this:
http://localhost/index.php?form=6
and the other pages with a query parameter don't show any errors.
This line of code in the cached version of alphabet.tpl comes right before line 351 and it doesn't throw an error:
Code: | <?php if (isset($_smarty_tpl->tpl_vars['form']->value)&&$_smarty_tpl->tpl_vars['form']->value==1){?>
<?php echo $_smarty_tpl->getSubTemplate ("language/widgets/".($_smarty_tpl->tpl_vars['language_widgets_1']->value).".tpl", $_smarty_tpl->cache_id, $_smarty_tpl->compile_id, 9999, null, array(), 0);?>
|
It's only showing the errors at localhost. At my domain name on the bluehost server, it doesn't show any errors. I am using a very old version, version Smarty-3.1.3 |
|
Back to top |
|
AnrDaemon Administrator
Joined: 03 Dec 2012 Posts: 1785
|
Posted: Wed Jun 23, 2021 4:11 pm Post subject: |
|
|
"Doesn't show errors" does not equal "no errors happening".
Show your template code, most likely you have something like
Code: | {if $form == 3} … {/if} | in there.
And I strongly suggest upgrading your Smarty right now. |
|
Back to top |
|
makamo66 Smarty Rookie
Joined: 21 Jun 2021 Posts: 5
|
Posted: Wed Jun 23, 2021 9:17 pm Post subject: |
|
|
Why do I need to upgrade my Smarty version if it's otherwise working fine? I think I found the problem based on your insight but I can't check it right now because I have to prepare for my bootcamp prep class that is starting in an hour. I will try to look at it and fix it tomorrow. |
|
Back to top |
|
makamo66 Smarty Rookie
Joined: 21 Jun 2021 Posts: 5
|
Posted: Thu Jun 24, 2021 11:48 am Post subject: |
|
|
Thanks, AnrDaemon, your idea was correct.
I had a whole bunch of elseif conditions in my template that didn't check whether the variable had been set or not. So I changed:
Code: | {if isset($form) && $form==1}
{include file="language/widgets/$language_widgets_1.tpl"}
{elseif $form==3}
{include file="language/widgets/$language_widgets_3.tpl"}
|
to:
Code: | {if isset($form) && $form==1}
{include file="language/widgets/$language_widgets_1.tpl"}
{elseif isset($form) && $form==3}
{include file="language/widgets/$language_widgets_3.tpl"}
|
That's just a snippet. There were actually more elseif conditions and none of them checked whether the variable had been set or not with isset. After I fixed this, all of the errors went away.
I still don't know why I need to upgrade my Smarty version. |
|
Back to top |
|
jonathan978123 Smarty n00b
Joined: 03 Mar 2021 Posts: 4
|
Posted: Wed Jun 30, 2021 5:16 pm Post subject: |
|
|
You'll want to upgrade smarty because you are using an old version.
Security fixes would be the main reason to keep smarty to date. |
|
Back to top |
|
makamo66 Smarty Rookie
Joined: 21 Jun 2021 Posts: 5
|
Posted: Mon Jul 19, 2021 11:51 pm Post subject: |
|
|
I'm having problems with my Smarty version on my localhost but it works for the website. My HTML is messed up on the localhost but I don't have the same stylesheet at the website so I don't know if my stylesheet is the problem or if my version is just too old. |
|
Back to top |
|
makamo66 Smarty Rookie
Joined: 21 Jun 2021 Posts: 5
|
Posted: Tue Jul 20, 2021 12:24 am Post subject: |
|
|
I commented out the stylesheet at localhost and I didn't have the same problem so my stylesheet is the problem, not the old version of Smarty. |
|
Back to top |
|
|