Jump to:

5450 Posts in 1672 Topics by 1197 members

Customising the CMS

SilverStripe Forums » Customising the CMS » Passing a variable to a function through the URL

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

Page: 1 2 3
Go to End
Author Topic: 4625 Views
  • Brig
    Avatar
    Community Member
    26 Posts

    Re: Passing a variable to a function through the URL Link to this post

    Sorry didn't spot that.

    Fixed that and removed the var_dump statements but it gives me the same error.

    To be honest I'm not really sure what I'm doing so I'm just trying to put your example together with the "Transforming a result to DataObjectSet" here: http://doc.silverstripe.com/doku.php?id=sqlquery.

    It's this line that gives the error:

    // template engine needs that to render RosterPage_alts.ss
          return array();

    Maybe I should just give up now hehe. I'm in way over my head with this code!

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Passing a variable to a function through the URL Link to this post

    That line looks just fine. Can you post your page-code to http://pastebin.com/ and post the link here? (Remove sensible information like db-connection params first)

  • Brig
    Avatar
    Community Member
    26 Posts

    Re: Passing a variable to a function through the URL Link to this post

    Sure here it is: http://pastebin.com/f4bfa766f

    Thanks so much for your patience.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Passing a variable to a function through the URL Link to this post

    Hey Brig

    There was just a semicolon (;) missing

    $this->memberData = $PlayerAlt; // assign the DataObjectSet to $this->memberData

    I also moved the DB config to a member variable, since you use that in other functions too.
    You also had a function to get each class individually... that's overkill. I rewrote the Members function, so that it does all that in one.
    In the template you can now use: $Members(Paladins) instead of $Paladins. To output all Members, just use $Members as before.

    Here's to complete class, hopefully there's no error in there
    http://pastebin.com/m65bc1dbd

  • Brig
    Avatar
    Community Member
    26 Posts

    Re: Passing a variable to a function through the URL Link to this post

    banal can't thank you enough! I think this works!
    The functions you cleaned up for me works perfectly, must neater than before

    When I try to use the alts function with the URL parameter I get:

    Website Error
    There has been an error

    The website server has not been able to respond to your request.

    Just as if the function isn't loading.

    What do you think could be wrong? Hopefully it's just something simple.

    Here's my Roster_alts.ss

    <div class="typography-site">
       <% if Menu(2) %>
          <% include SideBar %>
          <div id="Content">
       <% end_if %>
             
       <% if Level(2) %>
           <% include BreadCrumbs %>
       <% end_if %>
                   
                   <div class="rosterwrapper">
                      
                      <!-- Alts -->
                      <table class="rostertable" cellpadding="0" cellspacing="0">
                         <tr class="rostertr">
                            <td class="rostertdleft" colspan="4"><strong>Alts</strong></td>
                         </tr>
                      <% control MemberData %>
                            <tr class="rostertr">
                               <td class="rostername">$Name</td>
                               <td class="rosterlvl">$Level</td>
                               <td class="rosterrank">$Class</td>
                            </tr>
                      
                      <% end_control %>
                      </table>
                      
                   </div>      
       <% if Menu(2) %>
          </div>
       <% end_if %>
    </div>

    Thanks again banal. I owe you big time!

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Passing a variable to a function through the URL Link to this post

    That template looks fine to me.
    I guess there's a problem with the singleton('roster') statement. This will probably try to instantiate a class named "roster" which doesn't exist.. or doesn't have the required datafields.

    I modified the code slightly, so that the first result set is simply returned as DataObject:
    http://pastebin.com/m709e0480

    Let's hope this works, otherwise there's probably something wrong with the DB connection, but for other things it seems to work... If my new code doesn't work, you could switch on debugging to get a more detailed error message. To do so, add the following to mysite/_config.php

    Director::set_environment_type('dev');

    Edit: found another error in the code. Try the above (http://pastebin.com/m709e0480), it should be ok now

  • Brig
    Avatar
    Community Member
    26 Posts

    Re: Passing a variable to a function through the URL Link to this post

    It works now! You're officially my hero

    Have a look at: http://nda.johannesengstrom.com/guild-roster/alts/Bexie

    Just one thing missing. Currently it only selects one row in the database and displays it on the page so if there is more than one row it just takes the first one in the table.

    Like before I had

    $result = new DataObjectSet();
                foreach($query as $row) {
                $result->push(new ArrayData($row));

    I assume I need to fit foreach into the new SQLQuery as well?

    I haven't found an example for it yet but I imagine it's probably not a big thing.

  • banal
    Avatar
    Community Member
    901 Posts

    Re: Passing a variable to a function through the URL Link to this post

    Well, yes. I thought you were just interested in that single row...
    This code should return all results: http://pastebin.com/m25c6a1ce

    4625 Views
Page: 1 2 3
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.