Jump to:

3433 Posts in 1058 Topics by 734 members

Data Model Questions

SilverStripe Forums » Data Model Questions » relation

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

Page: 1
Go to End
Author Topic: 717 Views
  • snaip
    Avatar
    Community Member
    180 Posts

    relation Link to this post

    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

  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: relation Link to this post

    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

  • snaip
    Avatar
    Community Member
    180 Posts

    Re: relation Link to this post

    it doesnt work

  • swaiba
    Avatar
    Forum Moderator
    1786 Posts

    Re: relation Link to this post

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

    static $collection_controller_class = "KrakowProdukt_Controller";

    717 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.