explode() field data e.a.

A place for users and developers of the Xataface to discuss and receive support.

Postby dclijste » Sat Sep 08, 2007 12:30 pm

I created my own template for record-view.

There I want to ad a selectlist where data from $record->val('user_id') will be 'exploded' in diffrent options e.g:


{php}
$pieces = explode(", ", $record->val('owner_id'));
foreach ($pieces as $v) {
echo "$v";
$i++;}
{/php}


In the field owner_id will be a csv list of several id's e.g.: "5, 7, 21". These would be the owners (if there are more) from severals 'products' in this database. Next to this selectlist would be located a button to add information in a related database with the selected item of this selectlist and a different value from an inputbox.

Is there a proper way to do this in DF or else, is there a way to re-use the $record->val('user_id') value since between the {php} tags it wont be recognized anymore. I couldn't find a way to pass variables between what's inside and outside the {php} tags. (this seemed to me a smarty-related question but I couldn't find helpful information in the smarty documentation)

I know I can do (almost) the same with relations but making a diffrent table just for 1 field and linking everything together seems for me to much for what I need.
dclijste
 
Posts: 11
Joined: Wed Dec 31, 1969 5:00 pm

Postby dclijste » Sun Sep 09, 2007 7:17 am

OK, thanks to this howto I found the solition:
http://framework.weblite.ca/Members/dwe/customize%20a%20dataface%20application%20-%20I%20-%20single%20record%20view/?searchterm=df_display
___

{assign var="owner_id" value=$book->val('owner_id')}
{php}
echo $this->_tpl_vars[owner_id];
$pieces = explode(", ", $this->_tpl_vars[owner_id]);
foreach ($pieces as $v) {
echo "$v";
$i++;}
{/php}

___

This is still working around and not with the DF (& smarty) API but I think I can build my application by using this.
dclijste
 
Posts: 11
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Sun Sep 09, 2007 7:39 am

One recommendation.Ê It is best not to modify the template for something like this.Ê See http://framework.weblite.ca/documentation/how-to/list_tab for information on customizing the contents of the list tab.

One strategy to get an extra column is to use the __renderCell method on one of the columns from the table.

If you need to add an extra column for this you can create a dummy calculated field (http://framework.weblite.ca/documentation/manual/delegate_classes/method_reference/methodsql)

e.g.

__sql__ = "select *, col as dummy_column from tablename"

(note col must be an existing column in the table.Ê dummy_column can be any name you want to apply to the column.

Then you can override the display of this column using the

dummy_column__display() method

override the html display with

dummy_column__htmlValue()

or override how the cell is rendered in list mode with

dummy_column__renderCell()

-Steve

--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 28 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved