Jump to:

23450 Posts in 18899 Topics by 2877 members

General Questions

SilverStripe Forums » General Questions » URLSegment in Controler

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Page: 1
Go to End
Author Topic: 552 Views
  • Wezzlee
    Community Member
    28 Posts

    URLSegment in Controler Link to this post

    HI Guys,

    I am almost there. With the code below I manged to look for files in a certain directory.

    function getDirectoryList($directory)
    // create an object to hold directory list
       $icons = new DataObjectSet();
    // create a handler for the directory
    $handler = opendir($folder);

    // open directory and walk through the filenames
    while ($file = readdir($handler)) {

    // if file isn't this directory or its parent, add it to the results
    if ($file != "." && $file != ".." && substr($file,0,6)!="thumb_") {
          $icons->push(new ArrayData(array(
             'File' => $file


    // tidy up: close the handler

    // done!
    //return $results;
       return $icons;


    Now I only need to have the URL displayed in my HTML, but somehow it isn't displayed:

          <% control getDirectoryList($URLSegment) %>
                   <a href="/Silverstripe/themes/blackcandy/images/photos/$URLSegment/$File" rel="prettyPhoto[pp_gal]" $Title><img src="/Silverstripe/themes/blackcandy/images/photos/$URLSegment/thumb_$File" border="0" width="48" height="48" alt="van Leeuwen PHP test"></a>
                <% end_control %>

    What am I missing?

    I have tried this but this does not work either: http://www.silverstripe.org/template-questions/show/11215



  • Willr
    Forum Moderator
    5497 Posts

    Re: URLSegment in Controler Link to this post

    You cannot pass variables into other template variables (in 2.* versions anyway). Why don't you just get the URLSegment in your function?

    function getDirectoryList($directory) {
    $url = $this->URLSegment;

  • Wezzlee
    Community Member
    28 Posts

    Re: URLSegment in Controler Link to this post

    Thank you, Thank you very very much again - This works like a charm!

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.