|
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 |
lush_pierre Smarty n00b
Joined: 27 Nov 2004 Posts: 2
|
Posted: Sat Nov 27, 2004 11:57 am Post subject: Accesing multi-dimensional array params |
|
|
I've been struggling with this for a while...
I am writing a plugin function not too dissimilar from html_table called html_headed_table. the differences are that i want to pass a row of headings (no problem there) and use a 2d array of data to fill the table rather than use a single array based on passed col and row sizes.
The fact that this function has been implemented in this way suggests to me that perhaps you cannot use multimdimensional arrays with smarty?
Here is the code in my declared function:
extract($params);
echo("<br>{$data[0]} -- {$data[0][0]}");
$array = (array)$data;
echo("<br>{$array[0]} -- {$array[0][0]}");
$subarray = (array)$array[0];
echo("<br>{$subarray} -- {$subarray[0]}");
My template file contains:
{ html_headed_table data=$data, headings=$headings }
My php which includes the template contains:
$headings = array("Port ID", "Name");
$ports = array(array(1, "hiya"), array(2, "Hothing here"));
$PAGE->assign("title", "Ports");
$PAGE->assign("data", $ports);
$PAGE->assign("headings", $headings);
$PAGE->display("inventory.tpl");
So in this case, i'm passing a (manually created to take the db out of the equation) array of $ports to output in a table. Fairly simple i would have hoped, but i'm struggling to get the output i want!!!
This is what i'm getting in my browser:
A --
Array, -- A
Array -- Array,
I have tried using alternative methods to extract(), but no joy there either. I can understand all of the ouput except the last one, which by my logic, should print '1'.
Can anyone help me here? Is it not possible to assign() mutli dimensional arrays? |
|
Back to top |
|
boots Administrator
Joined: 16 Apr 2003 Posts: 5611 Location: Toronto, Canada
|
Posted: Sun Nov 28, 2004 3:46 am Post subject: |
|
|
Ack--your example is very difficult to follow. Why call the array $ports then call it $data in your template and then assign $array to $data? My head is swimming. Why bother showing things that have no relevance, like "title" and "headings"? Try and keep it plain and to the point for us if you want to get some relevant help.
Now the thing is, is that I can't duplicate your results. If you really used:
Code: | $data = array(array(1, "hiya"), array(2, "Hothing here")); |
then $data[0] is clearly = array(1, "hiya") and so:
Code: | echo("<br>{$data[0]} -- {$data[0][0]}"); |
produces:
which makes absolute sense.
Try putting a var_export($params['data']); in your plugin function to ensure you are getting the data you are expecting.
Unfortunately, I can't help any further since this inconsitency makes it unclear as to what is the issue in your code. FWIW, multi-dimensional arrays are no problem for Smarty. |
|
Back to top |
|
lush_pierre Smarty n00b
Joined: 27 Nov 2004 Posts: 2
|
Posted: Mon Nov 29, 2004 11:07 am Post subject: |
|
|
Thanks for the reply, sorry it wasn't the clearest description as it came straight out of my code. But thanks to you confirming the multidimensional arrays are no problem I perservered and found that the problem was in fact in this line:
Code: | { html_headed_table data=$data, headings=$headings } |
Where it was in fact the comma screwing everything up. |
|
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
|