[FX.php List] FX and Smarty dealing with arrays

Michael Layne fx at 9degrees.com
Wed Dec 21 20:50:37 MST 2005


Dan,

Thanks for the response...  My problem isn't with the states (my  
example works exactly as your does), but with using an FX query  
result.  Can you help there?  I'll try the Smarty list, but I thought  
the 'FX' piece might be more unique and perhaps scarce elsewhere...

Thanks again.


On Dec 21, 2005, at 12:22 PM, DC wrote:

> A few things:
>
> This is a great question for the smarty list. The people there are  
> very helpful.
>
> Also, there is a great wiki and forum too!
>
> The problem here is that you are putting $abbr into another array  
> on smarty assign.
>
> here's my code that works to create a state menu with selected state:
>
> php -
> <?php
> // load Smarty library
> require('/usr/local/smarty/libs/Smarty.class.php');
> $smarty=new Smarty();
> $smarty->template_dir = 'templates';
> $smarty->compile_dir = 'templates_c';
> $smarty->cache_dir = 'cache';
> $smarty->config_dir = 'configs';
> $states = array (
>     'AL' => 'Alabama',
>     'AK' => 'Alaska',
>     'AZ' => 'Arizona');
> $st = 'AZ';
> $smarty->assign('abbr',$states);
> $smarty->assign('st',$st);
> $smarty->display('stateselecttest.tpl');
> ?>
>
> tpl-
> {*stateselecttest.tpl*}
> <form>
> {html_options name=st options=$abbr selected=$st}
> </form>
>
> Ahhh.... smarty is nice and readable isn't it? Forms without  
> trouble. No cluttering HTML tags in the middle of PHP code. No  
> headaches trying to debug HTML tables that are constructed in while  
> loops, etc... caching mechanism built in so you can get over some  
> of the FMP speed limitations.
>
> best,
> dan
>
> Michael Layne had written:
>
>> Hi,
>> I know some of you are Smarty Template fans, so here's a question  
>> (and a bit of background).  First, I've tried to be thorough, so  
>> forgive the length of the post:
>> I finally took the leap and tried to implement Smarty on a new and  
>> somewhat sizable project.  It was a bit of a curve for a couple of  
>> days, but I do like the further separation of presentation and  
>> logic. (I've been rolling my own for some time) And yes, I've  
>> scoured the Smarty documentation, but only examples are dealing  
>> with MySQL/PostgreSQL.  That would be fine, but this solution is  
>> all FM7SA back-end.  I'm sure the root of my problem is my  
>> understanding (or lack thereof) of associative arrays as dished  
>> out by FM7SA's XML.
>> The challenge is creating a dynamic dropdown with FM data within  
>> a .tpl file.
>> First the normal PHP way: (I can do this all day long)
>>             <select name="accountCode">
>>             <option selected="selected">select...</option>
>>             <?
>>             foreach ($result['data'] as $option) {
>>                 echo "<option value=\"" . $option['account_codeID'] 
>> [0] . "\">" . $option['account_code'][0] . "</option>\n";
>>             }               ?>
>>             </select>
>> My first successful Smarty template:
>> data is an associative array of states:
>> $states = array (
>>     'AL' => 'Alabama',
>>     'AK' => 'Alaska',
>>     'AZ' => 'Arizona',
>> ...
>> .php code:
>> first:                  $smarty->assign('abbr',array($states));
>> then
>> .tpl code:
>>                   {html_options name=st options=$abbr selected=$st}
>> so... I cannot figure out how to get the above PHP/FX result in an  
>> array or format that will work with the Smarty template.  the  
>> closest I got was something like:
>>             <option "value="101">101</option>
>>             <option value="sample1"> sample1 </option>
>>             <option "value="102">102</option>
>>             <option value="sample2"> sample2 </option>
>> of course I'm looking for:
>>             <option value="101"> sample1 </option>
>>             <option value="102"> sample2 </option>
>> That's it.  Thanks very much in advance to anyone who can point me  
>> in the right direction.
>> Michael
>> Michael Layne  :  9 degrees development  :  www.9degrees.com  :   
>> 404.226.7835  
>> --------------------------------------------------------------------- 
>> ---
>> _______________________________________________
>> FX.php_List mailing list
>> FX.php_List at mail.iviking.org
>> http://www.iviking.org/mailman/listinfo/fx.php_list
>>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
>


Michael Layne  :  9 degrees development  :  www.9degrees.com  :   
404.226.7835

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.iviking.org/pipermail/fx.php_list/attachments/20051221/7c5d8c22/attachment.html


More information about the FX.php_List mailing list