...

View Full Version : problem in smarty .....



PHPycho
03-02-2007, 11:10 AM
Hello forum
i am getting problem in smarty
case:
wwwroot/mySite/admin has files like

-index.php
-listA.php
-listB.php

/templates/ folder has

-header.tpl
-footer.tpl
-index.tpl
-listA.tpl
-listB.tpl

index.php contains

<?php
//in upper section it includes all the class files and creates the respective objects
// neccessary processing goes here...
$smarty->display("index.tpl");
?>

index.tpl contains


{php}
if(isset($_GET['action']))
{
$filename = $_GET['action'].".php";
if(file_exists($filename))
{
include "$filename";
}
else
{
//error
}
{/php}

:::means it automatically includes the file as per $_GET action
suppose i clicked on the link ?action=listA then it auto includes the page listA.php which then display the array data in listA.tpl

problem:
It was working in normal case ie without using smarty but Now whenever i clik on the links
it shows:

Call to a member function selectAll() on a non-object in C:\Program Files\xampp\htdocs\mySite\admin\listA.php on line 39

i am not getting the solution please help.
Thanks in advance to all of you!!

GJay
03-02-2007, 01:10 PM
Having php in your templates isn't generally a good idea, why are you doing that? The whole point of using a templating system is to help you separate your logic from the presentation, resorting to {php} tags is a sign that you're doing something wrong.

The error is referring to a line in listA.php, would it perhaps be useful to have pasted that to look at?

Including files directly from user input is a really, really bad idea.

PHPycho
03-02-2007, 03:33 PM
Thanks dude
I got my problem solved
one more question:
how to perform the following with smarty ?
-

<?php
$count = 0;
while()
{
echo $count;
$count ++;
}
?>

Inigoesdr
03-02-2007, 07:59 PM
Smarty doesn't have a while function, but you should be able to use foreach (http://smarty.php.net/manual/en/language.function.foreach.php) or do the code in php and throw it back to Smarty.

GJay
03-04-2007, 12:18 AM
why would you want to do what you posted? I'm assuming there's meant to be a condition for the loop?


{section name=loop loop=10}
{$smarty.section.loop.index}
{/section}

will output 0-9.
Is that what you meant?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum