filling in values in link from db

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

filling in values in link from db

Postby Dataguru » Mon Mar 05, 2012 3:43 pm

Another clueless newby question.
I have in my functions.inc.php

Code: Select all
     function UserProgramID(){
   $user = getUser();
   $UserProgramID = ($user->val('ProgramID'));
   return $UserProgramID;
     }


How do I use that value in a template link to fill in the logged in user's program ID?
Code: Select all
<a href="{$ENV.DATAFACE_SITE_HREF}?-table=ProgGoals&-action=related_records_list&-relationship=Goals&-recordid=Programs?ProgramID=">List Program Goals</a>


Thanks,
Betty
Dataguru
 
Posts: 27
Joined: Mon Feb 20, 2012 8:12 am

Re: filling in values in link from db

Postby shannah » Tue Mar 06, 2012 10:16 am

Smarty is a bit of a pain in that it doesn't allow you to embed the output of PHP functions directly in the template (except in {if} tags for evaluating conditions).

You can call methods of objects that are part of the Smarty context and this is a way to get around many things. For example you can access the record of the currently logged in user (a Dataface_Record object) using the $ENV.user variable inside a smarty template. Therefore any method on this record could be called.

You could then create a custom field in your users table delegate class that you could access from the smarty template. E.g.:

Code: Select all
function field__my_program_id($record){
    return $record->val('ProgramID');
}


Then in your smarty template:
Code: Select all
{if $ENV.user}
    Program id is {$ENV.user->val('my_program_id')}
{/if}

You may notice, however, if you're using this approach you actually didn't need to create a custom field for the program ID since that field already exists. You could have just accessed the field directly from smarty:
Code: Select all
{if $ENV.user}
    Program id is {$ENV.user->val('ProgramID')}
{/if}



Best regards

Steve
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 6 guests

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