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.

DataObjectManager Module

Discuss the DataObjectManager module, and the related ImageGallery module.

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

IF conditions in DataObjectManager


Reply

4 Posts   833 Views

Avatar
snaip

27 September 2010 at 11:23pm (Last edited: 27 September 2010 11:24pm), Community Member, 180 Posts

Hi

I'm using DataObjectManager with SimpleTreeDropDownField to select Pages

<?php
class ModulBoxy extends DataObject {
   static $db = array (
'Nazwa' => 'Varchar'
   );
   
   static $has_one = array (
      'Strona' => 'Strona',
      'Page' => 'SiteTree'
   );
   
   public function getCMSFields_forPopup()   {
      return new FieldSet(
new TextField('Nazwa','Nazwa:'),
         new SimpleTreeDropdownField('PageID', 'Select Page:', 'SiteTree')
      );
   }
}
?>

Strona.php

public static $has_many = array(
'ModulBoxy' => 'ModulBoxy'
);

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

      $manager_boxy = new DataObjectManager(
         $this,
         'ModulBoxy',
         'ModulBoxy',
         array(
            'Nazwa' => 'Nazwa',
'PageID' => 'Page'
         ),
         'getCMSFields_forPopup'
      );

$fields->addFieldToTab("Root.Content.BoczneBoxy",$manager_boxy);

return $fields;
}

In Templete i get the values like:

Stona.ss

<% control ModulBoxy %>
$Page.Title
<% end_control %>

but if i want to do an IF condition the site is braking down

<% if Page.ClassName == Faq %>
do A function
<% end_if %>

it is so strange, in the next steps i have to do this

<% if Page.ClassName == Faq %>
<% include BoxFaq %>
<% end_if %>

<% if Page.ClassName == Contact %>
<% include BoxContact %>
<% end_if %>

BoxFaq.ss

<% control ModulFaq %> // another DataObjectManager with ImageGallery
$Title

<% control Attachment %>
%Title
<% end_control %>

<% end_control %>

Avatar
UncleCheese

28 September 2010 at 2:19am 4085 Posts

I'm not really seeing the issue??

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Avatar
snaip

28 September 2010 at 7:29pm Community Member, 180 Posts

i get blank page
try it yourself, maybe i'm doing something wrong

Avatar
UncleCheese

29 September 2010 at 2:15am 4085 Posts

Turn on your PHP error reporting. A blank page isn't very helpful!

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com