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.

Archive /

Our old forums are still available as a read-only archive.

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

Many-many relationship between two page objects


Reply


2 Posts   1254 Views

Avatar
sonet

Community Member, 33 Posts

5 October 2008 at 4:04am

Edited: 05/10/2008 7:29am

Hello...

I have tour and place page objects. I would like to have on a tour page places appear in order. By clicking on the place one should get to the place page, which shows all tours going through this place.

I was able to establish the many-many relationship between this two page objects by:

Tour.php

class Tour extends Page {

   static $many_many = array(
      'Places' => 'Place'
   );

   function getCMSFields() {

         $fields = parent::getCMSFields();

         $placesTablefield = new ManyManyComplexTableField($this,'Places','Place',
             array('Name' => 'Name'),'getCMSFields');
         //$placesTablefield->setAddTitle('A Place');

         $fields->addFieldToTab('Root.Content.Places', $placesTablefield);
         return $fields;
   }
}

Place.php

class Place extends Page {

   static $db = array(
         'Name' => 'Text'
   );

   static $belongs_many_many = array(
         'Places' => 'Place'
   );
   
   function getCMSFields() {
      $fields = parent::getCMSFields();
      $fields->addFieldToTab('Root.Content.Main', new TextField('Name'), 'Name');
      return $fields;
   }

}

1) I am using an additional field to show up in the CMS Places tab 'name'. How can I reference the place page name itself?

2) How can I prevent the 'Add' link showing up within the CMS Places Tab?

3) I need to have an additional numeric field in the Tour_Places table which will allow an ORDER BY. Can this be accomplished?

If so, a push in the right direction would be REALLY helpful. Thanks a lot.

Avatar
ChrisBryer

Community Member, 95 Posts

14 November 2008 at 6:59am

to answer question #2 (disable the 'add' button), add this line of code after you create the complextablefield:

$yourtable->setPermissions(array('delete', 'edit'));


(i got the answer from [url]http://www.silverstripe.com/website-authors-forum/flat/76012[/url])

i'd love to see answers for question #1 and #3 as well.

-Chris