Page 1 of 1

PostPosted: Thu Mar 08, 2007 11:46 pm
by perseqtor
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.

PostPosted: Fri Mar 09, 2007 12:34 am
by shannah

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

PostPosted: Sat Mar 10, 2007 12:35 am
by perseqtor
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.