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.

Reply

4 Posts   731 Views

Avatar
snaip

8 April 2010 at 11:09pm (Last edited: 8 April 2010 11:10pm), Community Member, 180 Posts

hi

i need your help

i have a class

class Formular extends DataObject {

   static $db = array (
   );
   
   static $has_one = array (
      'KrakowProdukt' => 'KrakowProdukt',
      'PolskaProdukt' => 'PolskaProdukt',
      'EuropaProdukt' => 'EuropaProdukt'   
   );

   public function formular() {
/* form definition */
}

}

and in each Produkt Page

class KrakowProdukt extends SiteTree {

   static $has_one = array(
      'Formular' => 'Formular'
   );

.....

}

how to get the formular() function in KrakowProdukt template ?

$formular

doesn't work

Avatar
swaiba

9 April 2010 at 12:20am Forum Moderator, 1796 Posts

Hi,

Something like this maybe?

class KrakowProdukt_Controller extends SiteTree_Controller
{
   function Formular()
   {
      return $this->Formular()->formular();
   }
}

This is not tested and I would have expected KrakowProdukt to extend Page. This idea is to place code for the view (template) into the controller. The Model part of silverstripe makes light weight of finding the has one relationship and then you call the function.

Hope this helps...

barry

Avatar
snaip

13 April 2010 at 10:08pm Community Member, 180 Posts

it doesnt work

Avatar
swaiba

14 April 2010 at 1:26am (Last edited: 14 April 2010 1:27am), Forum Moderator, 1796 Posts

inside class 'KrakowProdukt' you'll need the following line to connect the two together

static $collection_controller_class = "KrakowProdukt_Controller";