3063 Posts in 864 Topics by 646 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1465 Views |
-
Creating the Correct Link for a Dataobject

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!
-
Re: Creating the Correct Link for a Dataobject

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.
-
Re: Creating the Correct Link for a Dataobject

28 March 2009 at 9:08am
Perfect, that's exactly what I needed, and thanks for the tip about the EvenOdd variable - much cleaner!
-
Re: Creating the Correct Link for a Dataobject

2 April 2009 at 2:00am Last edited: 2 April 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 nowPeople (Faculty,Staff,Students)
Seminars
| 1465 Views | ||
|
Page:
1
|
Go to Top |


