Jump to:

3460 Posts in 1064 Topics by 739 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Creating the Correct Link for a Dataobject

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

Page: 1
Go to End
Author Topic: 1952 Views
  • Andrew Houle
    Avatar
    Community Member
    132 Posts

    Creating the Correct Link for a Dataobject Link to this post

    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!

  • UncleCheese
    Avatar
    4085 Posts

    Re: Creating the Correct Link for a Dataobject Link to this post

    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
    Avatar
    Community Member
    132 Posts

    Re: Creating the Correct Link for a Dataobject Link to this post

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

  • Victor
    Avatar
    Community Member
    128 Posts

    Re: Creating the Correct Link for a Dataobject Link to this post

    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

    1952 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.