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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Creating the Correct Link for a Dataobject


Go to End


4 Posts   5036 Views

Avatar
Andrew Houle

Community Member, 140 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 mysite.com/facultypage/showfaculty/1

My question is how to get the correct facultypage to print in the link? Because it is within a faculty control loop on the FacultyPage.ss 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>$Phone</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: mysite.com/facultypage/showfaculty/1 not this: mysite.com/showfaculty/1

Any ideas would be a big help, thanks!

Avatar
UncleCheese

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.

Avatar
Andrew Houle

Community Member, 140 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!

Avatar
Victor

Community Member, 128 Posts

2 April 2009 at 2:00am

Edited: 02/04/2009 5:34am

We are developing our Depart. Website using SilverStripe too. Probably we solved some problems you are thinking about and v.v.

If interested, drop email vivrii@gmail.com

PS Currently we are not ready to upload module, but when finish will surely do
We are ready to share our current work with other University Departments now

People (Faculty,Staff,Students)
Seminars