Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions /

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

URLSegment in Controler


Reply


3 Posts   604 Views

Avatar
Wezzlee

Community Member, 28 Posts

11 May 2012 at 6:52am

HI Guys,

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

function getDirectoryList($directory)
{
   $folder="/var/www/vhosts/wezzbite.nl/httpdocs/Silverstripe/themes/blackcandy/images/photos/".$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
closedir($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

Thanks

Wesley

Avatar
Willr

Forum Moderator, 5513 Posts

13 May 2012 at 6:26pm

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

Avatar
Wezzlee

Community Member, 28 Posts

15 May 2012 at 3:37am

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