21305 Posts in 5736 Topics by 2603 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 342 Views |
-
URLSegment in Controler

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
-
Re: URLSegment in Controler

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;
... -
Re: URLSegment in Controler

15 May 2012 at 3:37am
Thank you, Thank you very very much again - This works like a charm!
| 342 Views | ||
|
Page:
1
|
Go to Top |


