21487 Posts in 5783 Topics by 2621 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 393 Views |
-
SS3 Images from DataList

14 July 2012 at 12:58am
I'm trying to get several images from a DataList into a viewer. However, the function returns the values inside the 'File' table of SilverStripe.
my code:
FotoPagina.phpclass FotoPagina extends Page {
...public static $has_many = array(
'MyFotos'=>'FotoItem'
);
...
}
class FotoPagina_Controller extends Page_Controller {
...function getFotos(){
$list = DataList::create('FotoItem')->relation('Foto')->where('FotoItemID = '.$_GET['id']);
return $list;
}
...
}
FotoItem.phpclass FotoItem extends DataObject {
...
public static $many_many = array(
'Foto'=>'Image'
);
...
}
Page.ss<% loop getFotos %>
<li>
<a class="thumb" name="optionalCustomIdentifier $ID" href="$Filename">
<img src="$Filename"/>
</a>
</li>
<% end_loop %>SS will output the $ID and the Filename, but I need to get the image object, so I can set the $Image.setWidth(140) option. Is there a way to get this with the DataList, or is there any other option?
-
Re: SS3 Images from DataList

14 July 2012 at 2:29am
Within the <% loop %> structure you are within the scope of the Image. So theoretically you should be able to just do $setWidth(140) without the Image. preset. Haven't tried this though...
-
Re: SS3 Images from DataList

16 July 2012 at 8:19pm
Thanks! It works. Never thought it would be that easy...
| 393 Views | ||
|
Page:
1
|
Go to Top |

