Jump to:

7935 Posts in 1536 Topics by 943 members

DataObjectManager Module

SilverStripe Forums » DataObjectManager Module » How to get 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: 1060 Views
  • T3nD4n
    Avatar
    Community Member
    16 Posts

    How to get image Link to this post

    hi, mi English in to poor, but im going to try you understand me.

    i have a gallery holder whitch contains multiple gallerys with images.

    In my galery holder i want to show the title and an image of each galery, the image linked to the gallery.

    The Link an Name of each galery y can get with control children.
    but the problen comes when i want to show a image of the gallery, i cant figured how to get this image.

    here are my classes:
    HolderGalerias

    class holderGalerias extends Page {
    static $db = array(
    );
    static $has_one = array(
    );

    static $allowed_children = array('Galeria');
    }

    class holderGalerias_Controller extends Page_Controller {
    function getGalerias(){
          if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1)
             $_GET['start'] = 0;
          $SQL_start = (int)$_GET['start'];
          $doSet = DataObject::get(
          $callerClass = "Galeria",
          $filter = "",
          $sort = "",
          $join = "",
          $limit = "{$SQL_start},2"
          );
          return $doSet ? $doSet : false;
          //return $doSet->fotos();
       }   
    }


    Galeria

    class Galeria extends Page {
       
       static $has_many = array (
          'FotosGal' => 'imagenesGaleria',
    );
       
       static $db = array(
       );

       static $has_one = array(
       
       );
       
        public function getCMSFields(){
    $f = parent::getCMSFields();
    $manager = new ImageDataObjectManager(
    $this, // Controller
    'FotosGal', // Source name
    'imagenesGaleria', // Source class
    'Photo', // File name on DataObject
    array(
    ), // Headings
    'getCMSFields_forPopup' // Detail fields
    // Filter clause
    // Sort clause
    // Join clause
    );
    $f->addFieldToTab("Root.Content.Fotos",$manager);
    return $f;
    }
    }

    class Galeria_Controller extends Page_Controller {

       function fotos() {
          if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
          $SQL_start = (int)$_GET['start'];
          $doSet = DataObject::get(
             $callerClass = "imagenesGaleria",
             $filter = "`GaleriaID` = '".$this->ID."'",
             $sort = "",
             $join = "",
             $limit = "{$SQL_start},8"
          );
          return $doSet ? $doSet : false;
       }
    }


    imagenesGaleria

    class imagenesGaleria extends DataObject{
       static $db = array (
          'Title' => 'Varchar(250)',
       );
       
       static $has_one = array (
          'Galeria' => 'Galeria',
          'Photo' => 'Imagen',
       );
       
        public function getCMSFields_forPopup(){
    return new FieldSet(
             new TextField('Title'),
    new FileIFrameField('Photo')
    );
    }
    }

    any help would be apreciate!

  • T3nD4n
    Avatar
    Community Member
    16 Posts

    Re: How to get image Link to this post

    [SOLVED]

    this may help someone.

    I find the way to render one Image (DataObject) of a gallery from the holder gallerys

    My Class ImagenesGaleria:

    class imagenesGaleria extends DataObject{
       static $db = array (
          'Title' => 'Varchar(250)',
       );
       
       static $has_one = array (
          'Galeria' => 'Galeria',
          'Photo' => 'Imagen',
       );
       
       public function getCMSFields_forPopup(){
          return new FieldSet(
             new TextField('Title'),
             new FileIFrameField('Photo')
          );
       }
    }

    My Class Galeria:

    class Galeria extends Page {
       
       static $has_many = array (
          'FotosGal' => 'imagenesGaleria',
    );
       
       static $db = array(
       );

       static $has_one = array(
       );

       public function getCMSFields(){
    $f = parent::getCMSFields();
    $manager = new ImageDataObjectManager(
    $this, // Controller
    'FotosGal', // Source name
    'imagenesGaleria', // Source class
    'Photo', // File name on DataObject
    array(
    ), // Headings
    'getCMSFields_forPopup' // Detail fields
    // Filter clause
    // Sort clause
    // Join clause
    );
    $f->addFieldToTab("Root.Content.Fotos",$manager);
    return $f;
    }
       
       function forTemplate() {
          $galeria = DataObject::get_one('imagenesGaleria', "GaleriaID = $this->ID");
          return $galeria->renderWith('imagenesGaleria');
       }
    }

    class Galeria_Controller extends Page_Controller {

       function fotos() { // to render al the images in the template Galeria.ss in the page type Galeria.
          if(!isset($_GET['start']) || !is_numeric($_GET['start']) || (int)$_GET['start'] < 1) $_GET['start'] = 0;
          $SQL_start = (int)$_GET['start'];
          $doSet = DataObject::get(
             $callerClass = "imagenesGaleria",
             $filter = "`GaleriaID` = '".$this->ID."'",
             $sort = "",
             $join = "",
             $limit = "{$SQL_start},8"
          );
          return $doSet ? $doSet : false;
       }
    }

    My Class imagenesGaleria:

    class imagenesGaleria extends DataObject{
       static $db = array (
          'Title' => 'Varchar(250)',
       );
       
       static $has_one = array (
          'Galeria' => 'Galeria',
          'Photo' => 'Imagen',
       );
       
       public function getCMSFields_forPopup(){
          return new FieldSet(
             new TextField('Title'),
             new FileIFrameField('Photo')
          );
       }
    }

    And here is my holderGalerias.ss

    <% control Children %>    
       <div class="thumb">
          <a href="$Link" title="$Title"><img src="$Me" alt="" border="0" /></a>
          <div class="title">$Title</div>
       </div>   
    <% end_control %>

    Exist Me() method that returns $this, but if we use it in this case we will get this error.
    Object->__call(): the method 'fortemplate' does not exist on 'Galeria'
    for that i create the function forTemplate() inside the class Galeria:

    function forTemplate() {
       $galeria = DataObject::get_one('imagenesGaleria', "GaleriaID = $this->ID");
       return $galeria->renderWith('imagenesGaleria');
    }

    witch get one image of the galeria and render with imagenesGaleria.ss, found in templates/Includes, with the following code:

    $Photo.URL

    Hopefully someone will understand my poor English

    Bye.

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