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   780 Views

Avatar
snaip

Community Member, 180 Posts

8 April 2010 at 11:09pm

Edited: 08/04/2010 11:10pm

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

Forum Moderator, 1808 Posts

9 April 2010 at 12:20am

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

Community Member, 180 Posts

13 April 2010 at 10:08pm

it doesnt work

Avatar
swaiba

Forum Moderator, 1808 Posts

14 April 2010 at 1:26am

Edited: 14/04/2010 1:27am

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

static $collection_controller_class = "KrakowProdukt_Controller";