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

DC dan.cynosure at dbmscan.com
Thu Dec 22 07:25:22 MST 2005


Oh. It wasn't clear that was the problem since you didn't post any  
example with the FX result. In any case, there was an extra array  
wrapping the $states var and removing it won't hurt.

since each database is set up differently, it would help if you sent  
some bits from your output.

in the meantime, in order to get FX arrays to transform into something  
smarty likes try:

http://dbmscan.com/snippets/

go to FX and Smarty section and look at the examples on manipulating FX  
arrays to smarty style.

You'll see that I don't really assign FX data to smarty variables  
directly anymore. I just use the scripts there to automatically take  
every field and make an array that gets assigned to smarty. that lets  
me use filemaker fieldnames (with some small automatic modifications)  
as smarty variables.

HTH,
dan

On Dec 21, 2005, at 10:50 PM, Michael Layne wrote:

> 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 
>
> _______________________________________________
> FX.php_List mailing list
> FX.php_List at mail.iviking.org
> http://www.iviking.org/mailman/listinfo/fx.php_list
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 5375 bytes
Desc: not available
Url : http://www.iviking.org/pipermail/fx.php_list/attachments/20051222/51aefdca/attachment-0001.bin


More information about the FX.php_List mailing list