Idea for for array handling in Smarty
| From: | Andr� Rabold | Date: | Fri, 28 Feb 2003 07:38:51 +0000 |
| Subject: | Idea for for array handling in Smarty | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-864@lists.php.net to get a copy of this message | ||
Hi folks,
I just had an idea how to improve array handling using Smarty. Here's my
problem:
I have a form for example (kind of pseudocode using my own form plugins):
{form}
{form_input type="combobox" options=$status_options value=$status_id}
{/form}
$status_options is an assoc array of this kind: array ( $id =>
$description);
This works for me perfectly. That's not the problem... ;-)
Now what I want to do:
Instead if assigning $status_options assign an array $states which is a
result of a MySQL query for example:
$states = array(
array("id" => "0815", "description" => "unassigned",
"icon" =>
"unassigned.png", ... ),
array("id" => "4711", "description" => "foo",
"icon" => "bar.png", ... ),
...
);
Now it would be great if I could use something like this in Smarty:
{form}
{form_input type="combobox" option_keys=$states.id
option_values=$states.description value=$status_id}
{/form}
Notice this syntax: $status.id and $status.description
Both should result in an array of the "id" column and the "description"
column instead of empty values. This would be a real enhancement an a nice
feature.
What do think?
A solution for this could be to first check if the array contains an index
"id" and return it if it exists. Otherwise check if the array contains other
arrays with this index and return the whole column.
Good or bad?
André