Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Creating the Correct Link for a Dataobject

Go to End

4 Posts   2647 Views

Andrew Houle

Community Member, 134 Posts

28 March 2009 at 2:28am

I have the following setup. A FacultyPage page type and a Faculty dataobject. A FacultyPage has many Faculty and a Faculty has one Faculty Page. Within the Faculty Page controller I have the following code...

function showfaculty() {
		if($id = Director::urlParam('ID')) { // check to see we have been passed an ID
			$showfaculty = DataObject::get_by_id("Faculty", $id);
   			return $this->customise(array('Faculty' => $showfaculty))->renderWith(array('FacultyMember',  'Page'));

This works fine with a url like

My question is how to get the correct facultypage to print in the link? Because it is within a faculty control loop on the page it won't display the url with the facultypage part, nor can I call something like $URLSegment. Here is the template code...

<% control Faculty %>
<tr class="<% if Even %>even<% else %>odd<% end_if %>">
<td><a href="showfaculty/$ID">$FirstName $LastName</a></td>
<td class="last"><a href="mailto:$Email">$Email</a></td>
<% end_control %><!-- end of Faculty control -->

I need this part: <a href="showfaculty/$ID"> to print: not this:

Any ideas would be a big help, thanks!


Forum Moderator, 4102 Posts

28 March 2009 at 8:53am

You need to overload your Link() method on the Faculty object

function Link()
return $this->FacultyPage()->Link("showfaculty")."/".$this->ID;

You can also use the $EvenOdd template variable and clean up those if blocks.

Andrew Houle

Community Member, 134 Posts

28 March 2009 at 9:08am

Perfect, that's exactly what I needed, and thanks for the tip about the EvenOdd variable - much cleaner!


Community Member, 128 Posts

2 April 2009 at 2:00am

Edited: 02/04/2009 5:34am