Setting default select setting from users table

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

Postby perseqtor » Thu Mar 08, 2007 11:46 pm

First off, I want to say that this is the holy grail of PHP/Mysql development apps. I'm a complete noob and yet I was still able to set up
a working web database in an afternoon with some fantastic features for the end user.

I'm wondering if I can I have the select widget set a default selection using the logged in user's userid number from the users table.
I'm sure there's a ridiculously easy answer but not being a trained programmer of any sort, I'm not seeing it.
perseqtor
 
Posts: 11
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Mar 09, 2007 12:34 am

Hi John,

Thanks for the kind words on the framework.
As for your question, the answer is 'YES'.
You can set the default value for any field programmatically by implementing a method named '%fieldname%__default".
e.g.
If you want to set the default value for a field named 'owner_id' in the table 'jobs', then you would implement the following method in the tables/jobs/jobs.php file (i.e. the jobs table delegate class):
function owner_id__default(){
ÊÊÊ $auth =& Dataface_AuthenticationTool::getInstance();
ÊÊÊ $user =& $auth->getLoggedInUser();
ÊÊÊ if ( isset($user) ) return $user->val('userid');
Ê Ê return null;
}
The above function will cause the owner_id field to have a default value of the currently logged in user's user id.Ê If no user is logged in, then it just has a null default value.
Hope this helps a little.
-Steve
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby perseqtor » Sat Mar 10, 2007 12:35 am

The method worked perfectly. I incorporated similar defaults throughout my data entry pages, despite my almost pathological fear of
object oriented programming. Once again, your ability to "dumb it down" to allow non-programmers to so effectively utilize this framework is inspiring. Keep up the great work.
perseqtor
 
Posts: 11
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 7 guests

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