21280 Posts in 5729 Topics by 2600 members
General Questions
SilverStripe Forums » General Questions » How to get the name corresponding to ID from other table?
General questions about getting started with SilverStripe that don't fit in any of the categories above.
Moderators: martimiz, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
|
Page:
1
|
Go to End | |
| Author | Topic: | 699 Views |
-
How to get the name corresponding to ID from other table?

20 August 2011 at 8:04am
Hello,
I have a table which contains only ID's from other tables and some additional data. Now I read this table, and I find a record, for instance
1, 10, 13
2, 15, 26
.
.
.Now this is found using DataObject::get('CallerName'); inside the SomePage_Controller class
Offcourse I want to display in my templatefile not these rows, but the corresponding names which are stored in other tables (for instance Member, Articles, ....). How can I achieve this? just can't solve this at the moment.
Thanks for you help,
Maurice -
Re: How to get the name corresponding to ID from other table?

20 August 2011 at 8:44am
Hi Maurice,
something like this...
templatefile.ss
<% control CallerName %>
has_one member -
$Member.Firstnamehas_many Articles -
<% control Articles %>
$Name
<% end control %><% end control %>
more information in the tutorials and in the documentation about templates.
Barry
-
Re: How to get the name corresponding to ID from other table?

20 August 2011 at 10:11pm
Thanks for your help, however I still do not get it working. Maybe I am referencing wrong. I will give some more details of the situation at hand:
Profile.php
class Profile extends Page {
}class Profile_Controller extends Page_Controller {
function CurrentSubscriptions() {
// s11s = s ubscription s
$cMember = Member::currentUserID();
$s11s = DataObject::get("DanceCouples","PartnerAID = {$cMember} OR PartnerBID = {$cMember}");
return $s11s;}
}Than I have the following code that creates the Model for the couples of persons:
class DanceCouples extends DataObject {
static $db = array(
'DansNiveau' => "Int"
);// Een lid kan meerdere koppels vormen
static $has_one = array(
'PartnerA' => 'DanceMemberInfo',
'PartnerB' => 'DanceMemberInfo'
);And the following Model for 'DanceMemberInfo':
class DanceMemberInfo extends Member {
static $db = array(
'Voorletters' => 'Varchar',
'Geslacht' => "Enum('m,v')",
'Adres' => 'Varchar',
'Postcode' => 'Varchar',
'Plaats' => 'Varchar',
'Telefoon' => 'Varchar',
'XtraCardNr' => 'Varchar'
);// Meerdere dansniveaus per lid toegestaan
static $has_many = array(
'DanceCouples' => 'DanceCouples',
);
}The IDs which 'DansNiveau' refers to are created here:
class DanceCourses extends DataObject {
static $db = array(
'Name' => 'Varchar'
);
}Is this a proper way of creating a model, so I can read all data to the template? How can I reference to it? I tried using the advanced-template reference of SS, but it did not help for me. Could you maybe give some suggestions?
Thanks a lot!
Maurice -
Re: How to get the name corresponding to ID from other table?

21 August 2011 at 7:58am
I think you forgot to add a has_one or has_many relationship from DanceCouples to DanceCourses.
| 699 Views | ||
|
Page:
1
|
Go to Top |



