Jump to:

3375 Posts in 999 Topics by 712 members

Data Model Questions

SilverStripe Forums » Data Model Questions » access a outside $Link from within the control

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

Page: 1
Go to End
Author Topic: 1456 Views
  • Ben_W
    Avatar
    Community Member
    79 Posts

    access a outside $Link from within the control Link to this post

    I have three page type, 'MainPage' has 5 'PageHolder', each 'PageHolder' has number of 'QuestionPage'
    on the MainPage.ss I need to access $link of current child 'PageHolder' $Link, inside the custom control of 'firstQuestion'

    <% if Children %>
       <% control Children %>
       
          <% if firstQuestion %>
          <p>
          <h2>$PersonaType</h2><br>
             <% control firstQuestion %>
             
             
             <h4>"$Question"</h4> <br>
             $Enquirer <br><br>
             
             Previous Questions:
             
             
             //I need to access this link
             <a href="$Children.Link">View All</a>
             
                
              <br><br>
             <% end_control %>
             
                <% if secondAndThirdQuestion %>
                <% control secondAndThirdQuestion %>
                   <a href="$Link">$Question</a> <br>
                   
                <% end_control %>
                <% end_if %>
          </p>
          <br>   
          <hr>
          <br>
          <% end_if %>
       
       <% end_control %>
    <% end_if %>

    the firstQuestion is inside the 'PageHolder'
    public function firstQuestion(){
          return DataObject::get("QuestionPage", "ParentID={$this->ID}", '', '', '0, 1');
       }

    I am trying to add another function
    public function currentPageHolder(){
          return $this->Link();
          
       }

    Could someone please shed some light on this. Thank you.

  • Pigeon
    Avatar
    Community Member
    243 Posts

    Re: access a outside $Link from within the control Link to this post

    Right, I don't think what you are trying to achieve is entirely clear.

    Whatever it is, $Children.Link won't work as Children is a DataObjectSet, so it won't have a link associated.

    If you want the link of the current Child you are 'controlling' then it is $Link.

    If you want the Link of the page you are currently on (ie: The holder page) then you would use $Top.Link - but this will only show the link to the current page. So I'm not sure that is really what you want.

    Anyway, there is no need for a custom method (currentPageHolder).

    Hope that helps

  • Ben_W
    Avatar
    Community Member
    79 Posts

    Re: access a outside $Link from within the control Link to this post

    Thanks for the reply. I can't use $Link, because it will return the firstQuestion page Link, I can't use $top.Link, because not only it break out the firstQuestion control, it also break out the Children control, and return the MainPage Link. I have tried them both before, it won't work. What I am after is the Children's Link.

    I have managed to get it by using $Parent.Link, you are right, I don't need to write a custom function. Cheers.

    1456 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.