Does not allow '0' as index in value-lists

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

Does not allow '0' as index in value-lists

Postby Atochex » Tue Apr 08, 2008 4:17 pm

Hi,

I have a site engine that uses column definitions 'Tags', 'Banner', 'Side Bar', and 'Content'. Column '0' loads site specific template tags that will be loaded before any other columns.

I am looking for a way to allow a value-list to accept the index value '0'.

Code: Select all
[Columns]
0 = Tags
1 = Banner
2 = Side Bar
3 = Content


The entry above in the valuelists.ini file throws this error in xataface:

Warning: Invalid argument supplied for foreach() in D:\...\xataface\Dataface\Table.php on line 1111

It has to do with '0' as an index.

Is there a way to allow '0' in a valuelist without having to create another mapping table specifically for this valuelist to map col_ID to col_name?

Thank you very much for your great support.

Chris
Atochex
 
Posts: 9
Joined: Mon Apr 07, 2008 8:35 pm

Postby shannah » Tue Apr 08, 2008 7:14 pm

See the following thread for a discussion on this issue:
http://xataface.com/forum/viewtopic.php?t=3808#19038
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Does not allow '0' as index in value-lists

Postby Atochex » Wed Apr 09, 2008 12:47 am

The question was is there a way to allow '0' in a valuelist without having to create another mapping table specifically for this valuelist to map col_ID to col_name?


The answer is No, there is no other way then moving the value-list into a table and changing the valuelists.ini from static definition to a dynamic sql call:

Code: Select all
[Columns]
__sql__ = "SELECT col_ID, col_name FROM Columns ORDER BY col_name"


That would be worth fixing since '0' is a valid entry for option-lists in HTML forms. I like to keep my number of tables as little as possible.

Chris :wink:
Atochex
 
Posts: 9
Joined: Mon Apr 07, 2008 8:35 pm

Postby shannah » Wed Apr 09, 2008 11:03 am

That would be worth fixing since '0' is a valid entry for option-lists in HTML forms.


Yes. Sadly this is one of the limitations of using INI files. I chose them for their simplicity and still think that they are nicer to work with for most config things than delving into XML.

There is a workaround of course, which is to define the valuelist in the application delegate class (or the table delegate class).

E.g.

Code: Select all
function valuelist__Tables(){
    return array(
        0 => 'All',
        1 => 'Table 1',
        2 => 'Table 2'
    );
}


Since this method is called each time your valuelist is desired, you should implement some kind of caching if this method is going to do any real work.

e.g.

Code: Select all

function valuelist__Tables(){
    static $values = -1;
    if ( $values == -1 ){
        $values = array(0 => 'All');
        $res = mysql_query("select * from  ...", df_db());
        while ( $row = msyql_fetch_row($res) ){
            $values[$row[0]] = $row[1];
        }
    }
    return $values;
}


As Xataface's config loading system was designed to be pluggable, it is possible that in the future there will be alternative formats for config files (e.g. XML or SQL) but for now, this is the situation.

Best regards

Steve
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby Atochex » Wed Apr 09, 2008 4:32 pm

Steve,

using the delegate Class for a particular table was the answer. I have placed the file Block_location.php in the folder for the particular table, in this case Block_location, and it works like a charm. No need for caching though since I am using this for the back-end use (Admin) and not front-end.

Code: Select all
class tables_Block_Location {

   function valuelist__Display(){
      return array(
        0 => 'Disabled',
        1 => 'Enabled'
      );
   }
   function valuelist__Columns(){
      return array(
        0 => 'Tags',
        1 => 'Banner',
        2 => 'Side Bar',
        3 => 'Content'
      );
   }
}


Thanks Steve,

Chris :lol:
Atochex
 
Posts: 9
Joined: Mon Apr 07, 2008 8:35 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 13 guests

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