Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Data Model Questions /

CheckboxSetField , how to display data in template ?


Reply


3 Posts   1871 Views

Avatar
snaip

Community Member, 180 Posts

13 April 2010 at 8:52pm

Edited: 13/04/2010 8:53pm

hi

in CMS i have

static $has_many = array(
   'WyroznioneProdukty' => 'SiteTree'
);
...

function getCMSFields() {
$fields = parent::getCMSFields();

$KrakowProduktList = DataObject::get('KrakowProdukt');
$fields->addFieldToTab("Root.Content.WyroznijNaStronieKategorii",new CheckboxSetField('WyroznioneProdukty','Select all related pages to appear in the main page', $KrakowProduktList));       

return $fields;
}

now how to display checked elements in CheckboxSetField in templetes ?

i tried to

<% control WyroznioneProdukty %>
<p>$Title</p>
<% end_control %>       

but it displays all elements which are in the CheckboxSetField (checked and unchecked)

Avatar
Willr

Forum Moderator, 5513 Posts

13 April 2010 at 10:21pm

The has_many should only return the saved options. Do you have a has one relationship on the other side? (Has many must has a related has one).

Avatar
snaip

Community Member, 180 Posts

13 April 2010 at 10:40pm

this is all my code

<?php

class Krakow extends SiteTree {

   static $db = array(
      'SG1Brak' => "Boolean",
      'SG2Brak' => "Boolean",
      'SG3Brak' => "Boolean"   
   );
   
   static $has_one = array(
      'SG1' => 'SiteTree',
      'SG2' => 'SiteTree',
      'SG3' => 'SiteTree',
      'StronaGlowna' => 'StronaGlowna'
   );
   
   static $has_many = array(

      'WyroznioneProdukty' => 'SiteTree'
   );
   
   static $allowed_children = array('KrakowProdukt');

   function getCMSFields() {
      $fields = parent::getCMSFields();      

      $KrakowProduktList = DataObject::get('KrakowProdukt');

      
      $fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new TreeDropdownField('SG1ID','Produkt pierwszy:','SiteTree'));
      $fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new CheckboxField('SG1Brak','WyÅ›wietl ten element'));
      $fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new TreeDropdownField('SG2ID','Produkt drugi:','SiteTree'));
      $fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new CheckboxField('SG2Brak','WyÅ›wietl ten element'));
      $fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new TreeDropdownField('SG3ID','Produkt trzeci:','SiteTree'));
      $fields->addFieldToTab("Root.Content.PromujNaStronieGlownej", new CheckboxField('SG3Brak','WyÅ›wietl ten element'));    

      $fields->addFieldToTab("Root.Content.WyroznijNaStronieKategorii",new CheckboxSetField('WyroznioneProdukty','Select all related pages to appear in the right column', $KrakowProduktList));       

      
      return $fields;
   }

}

class Krakow_Controller extends Strona_Controller {

}
?>