Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » Gallery. Get the first Image.

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Page: 1
Go to End
Author Topic: 677 Views
  • kondor
    Avatar
    Community Member
    9 Posts

    Gallery. Get the first Image. Link to this post

    Hi I Use DataObjectManager Modul

    And I create a realy simple Gallery, and everything works perfect, but now i want to make some kind of Holder lets say a KatalogImageHolder.php where the children are KatalogImagePage, where I want to show only the first Image of the KatalogImagePage. And I have no Idea how can I do that stuff (I Know this is not so really appended from DataObjectManager Modul)

    Please Help me to get it work

    KatalogImageHolder.php looks like this

    class KatalogImageHolder extends Page {

       static $db = array(
       );

       static $has_one = array(
       );
       
       static $allowed_children = array('KatalogImagePage');
    }
    ….

    and KatalogImagePage.php like this

    class KatalogImagePage extends Page
    {
       static $has_many = array (
          'KatalogImages' => 'KatalogImage'
       );
       
    // Here go, I don't know how to make it run,
    public function getFirstPhoto(){
             return $this->KatalogImages[0]; //that doesn't work
    }

       
    ...

    @UncleCheese. My Post has been duplicated, please delete one of them

  • UncleCheese
    Avatar
    4085 Posts

    Re: Gallery. Get the first Image. Link to this post

    In the template:

    $KatalogImages.First

    In the controller:

    $this->KatalogImages()->First();

  • kondor
    Avatar
    Community Member
    9 Posts

    Re: Gallery. Get the first Image. Link to this post

    Oh men, @UncleCheese

    I knowed, I've read about this, but many , many months ago ;)

    It is working now, thanks for your help

    677 Views
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.