custom record title using getTitle
Archived from the Xataface Users forum.
razzetto — Sat Jul 21, 2012 2:23 am
hi steve. hi all.
i’m trying to get a custom title for the “current record” in a table (this table is named interviews) .
In this table i have a user_id and this table has a relationship with another table,
where this user_id has a surname, name etc.
now.. i would like, on the interviews table, to show as a title something like :
‘interview of’. name and surname corresponding to this user id.
the only thing i guess is that i should use the function (in a delegate class) getTitle.
i tried with this
- Code: Select all
- `<?
class tables_interviews {function getTitle(&$record){
return ‘interview of’ . $record->val(‘user_id’);
}
}`
but of course since $record refers to the current record i just get : interview of 1, interview of 2, etc.
Is there a variable i can use instead of $record or i should go for a custom query?
thanks for any hint!
shannah — Sat Jul 21, 2012 11:37 am
In cases like this, I generally graft the fields that I need onto the table, then use those fields inside the getTitle() method. E.g.
In the fields.ini file for the interviews table:
- Code: Select all
__sql__ = "select i.*, u.name as user_first_name, u.surname as user_last_name from interviews i left join users u on i.user_id=u.user_id"
This will create two read-only fields in the interviews table: user_first_name and user_last_name that you can use just like normal fields. Then your getTitle() method would be like:
- Code: Select all
function getTitle($record){ return 'interview of '.$record->val("user_first_name").' '.$record->val('user_last_name'); }
-Steve
razzetto — Sat Jul 21, 2012 2:04 pm
brilliant!
thanks for your excellent support, steve.
paolo.