php - Silverstripe 3.0 return dataobjects and page url's in one function -


i using silvertripe 3.0 , have simple page setup has couple children pages. children pages have data objects contain images, trying both images , url of children page appear on parent page. have following code in template:

<% loop $children %>     <a href="$link">$title</a> <% end_loop %>  <div id="whiskymaingallery">      <% control whiskygallery %>         <div class="item">              <a href="$whiskypageid">$slide.setratiosize(220,178)</a>          </div>      <% end_control %>  </div> 

both of these controls work expected, try combine them data object image whiskygallery control url can call following in template:

<% control joinedstuff %>     <a href="$childpageurl">$dataobjectimage</a> <% end_control%> 

any appreciated!

here whiskypage class:

class whiskypage extends page {      public static $db = array(         'abv'       => 'text',         'colour'    => 'text',         'aroma'     => 'htmltext',         'taste'     => 'htmltext',         'finish'    => 'htmltext'     );      public static $has_many = array(         'tastingawards' => 'tastingaward',         'whiskyimages'  => 'whiskyimage'     );     public function getcmsfields() {          $fields = parent::getcmsfields();          $gridfieldconfig = gridfieldconfig_recordeditor::create();          $gridfieldconfig->addcomponent(new gridfieldbulkeditingtools());         $gridfieldconfig->addcomponent(new gridfieldsortablerows('sortorder'));             $gridfield = new gridfield("tastingawards", "tasting awards", $this->tastingawards()->sort("sortorder"), $gridfieldconfig);          $gridfieldconfig2 = gridfieldconfig_recordeditor::create();          $gridfieldconfig2->addcomponent(new gridfieldbulkeditingtools());         $gridfieldconfig2->addcomponent(new gridfieldbulkimageupload());            $gridfieldconfig2->addcomponent(new gridfieldsortablerows('sortorder'));            $gridfield2 = new gridfield("whiskyimages", "whisky images", $this->whiskyimages()->sort("sortorder"), $gridfieldconfig2);          $fields->addfieldtotab('root.tasting notes', new textfield('abv', 'abv'));         $fields->addfieldtotab('root.tasting notes', new textfield('colour', 'colour'));         $fields->addfieldtotab('root.tasting notes', new htmleditorfield('aroma', 'aroma'));         $fields->addfieldtotab('root.tasting notes', new htmleditorfield('taste', 'taste'));         $fields->addfieldtotab('root.tasting notes', new htmleditorfield('finish', 'finish'));          $fields->addfieldtotab('root.tasting awards', $gridfield);         $fields->addfieldtotab('root.whiskyimages', $gridfield2);          return $fields;      }  } 

my whiskyimage dataobject

class whiskyimage extends dataobject {      public static $db = array(         'sortorder'   => 'int',       'title'       => 'varchar',       'featured'    => 'boolean'     );      // one-to-one relationship whisky page     public static $has_one = array(     'slide'         => 'image',     'whiskypage'    => 'whiskypage'     );      // tidy cms not showing these fields     public function getcmsfields() {         $fields = parent::getcmsfields();         $fields->removefieldfromtab("root.main","whiskypageid");         $fields->removefieldfromtab("root.main","sortorder");          $fields->addfieldtotab('root.main', new checkboxfield('featured', 'featured'));          return $fields;     }      // tell datagrid fields show in table     public static $summary_fields = array(         'id'         => 'id',        'title'      => 'title',        'thumbnail'  => 'thumbnail'     );      // function creates thumbnail summary fields use     public function getthumbnail() {          if ($image = $this->slide()->id) {              return $this->slide()->setwidth(80);          } else {             return '(please upload image)';          }     }  } 

the whiskylandingpage has it's own class, nothing interesting in it, except custom function return images

public function getwhiskygallery() {     return whiskyimage::get()->filter(array('featured' => 1))->sort("sortorder"); } 

hope makes bit more sense!

first, should use loop instead of control in templates

second, joining dataobjects , pages seems rather bad idea , run problems. why not loop pages , loop dataobjects?

like so:

<% loop $children %>     <a href="$link">$title</a>     <ul>        <% loop $whiskyimages %>            <a href="$top.link" title="link whisky page">image: $title</a>            <a href="$whiskypage.link">this link link wisky page</a>            $slide.setratiosize(220,178)        <% end_loop %>     </ul> <% end_loop %> 

// edit:

in example loop list of whiskyimage objects, can this:

<div id="whiskymaingallery">     <% loop whiskygallery %>         <div class="item">             <a href="$whiskypage.link">$slide.setratiosize(220,178)</a>         </div>     <% end_loop %> </div> 

Comments

Popular posts from this blog

c++ - CryptStringToBinary API behavior -

java.util.scanner - How to read and add only numbers to array from a text file -

iphone - Three second countdown in cocos2d -