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.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Front End ComplexTableField- Page Not Found


Reply

4 Posts   678 Views

Avatar
CHD

4 March 2012 at 11:08am Community Member, 218 Posts

can anybody help with this?

I've go a front end complextable (or dataobjectmanager - either is fine) and it lists my dataobjects fine, but when i click them or try to add a new one it just ends with "page not found"

here's my code:

<?php
class Rates extends DataObject {
   public static $db = array(
      
      "PricePerNight" => "Currency",
      "dateStart" => "Date",
      "dateEnd" => "Date"
   );

   public static $has_one = array(
      "Apartment" => "Apartment"
   );
   
   public static $has_many = array(
   );
   

   
   public function getCMSFields_forPopup() {
      return new FieldSet(
         new TextField('PricePerNight'),
         new DatePickerField ('dateStart','Date of arrival'),
         new DatePickerField ('dateEnd','Date of departure')
      );
   }

}

*********************************************

   function RatesForm(){
   $Apartment = $this->getApartment();   
   $Manager = new ComplexTableField(
      $this,
      'Rates',
      'Rates',
      array('dateStart' => 'dateStart'),
      'getCMSFields_forPopup',
      'ApartmentID = ' . $Apartment->ID
      );
   $Manager->setParentClass('Rates');
   $Manager->setPermissions(array("show","edit", "add"));
   
   $fields = new FieldSet(
new HiddenField('ID', ''),
$Manager
);

   
   return new Form($this, 'RatesForm', $fields, new FieldSet());
}

I'm guessing the issue is because i'm generating the form on an external page type to where the "Rates" are initially managed. so is it to do with the controllers?
I think the problem may lie here:

$Manager = new ComplexTableField(
      $this,

Does the $this need to be something else?

I have the following relationships.
"Apartments" are dataobjects - they $has_many "Rates"
"Rates" are dataobjects - they $has_one "Apartment"

And im tryng to have a form that loads on my front end "edit" page with a URL like this: mysite.com/account/your-listings/rates/apartment-name

It all shows up fine in the front end, and ONLY the rates that apply to that Apartment appear, it's just I cant click/edit/delete them.

thanks in advance for your help!

Avatar
pbz

24 March 2012 at 2:45pm Community Member, 5 Posts

Has anyone figured out a solution to this? I'm having a similar problem.

Thanks.

Avatar
Chris_Bryer

30 March 2012 at 4:21pm Community Member, 35 Posts

you'll need to use DOM instead of CTF (i've noticed the Ajax callback method is broken on CTF when you try to delete), and for the source class in the constructor method, use $this->dataRecord instead of $this...

$Manager = new DataObjectManager(
$this->dataRecord,
...

-Chris

Avatar
CHD

31 March 2012 at 12:23am (Last edited: 31 March 2012 12:25am), Community Member, 218 Posts

Hmmmm I have it almost working. Well I can add objects via the frontend DOM now, but I cant figure out the relationships.

here's my code:

   function RatesForm(){
   $Apartment = $this->getApartment();   
   $Manager = new DataObjectManager(
      $this->dataRecord,
      'Rates',
      'Rates',
      array('dateStart' => 'dateStart'),
      'getCMSFields_forPopup',
      'ApartmentID = ' . $Apartment->ID
      );

   $Manager->setPermissions(array("show","edit", "add"));   
   $fields = new FieldSet(
$Manager
);   
   if($Apartment)   {
   $fields->push(new HiddenField('ID','ID',$Apartment->ID));
   }
   
   return new Form($this->dataRecord, 'RatesForm', $fields, new FieldSet());
}          

So that lists all the rates related to this apartment fine, but I can't edit them, clicking them throws up this error: [Notice] Trying to get property of non-object which is because I have the filter in there based on a $this request for apartment. as soon as you click the dataObject the URL changes and as a result there's no apartment to get an ID from.
As you can see I've put the Apartment ID into the form with a hidden field, but I can't figure out how to pass that to the DOM pop up.... if I take out the filter I can add/edit rates fine, but I need to make sure the user only see's the rates related to this apartment. I hope that makes sense!

can anybody shed any light on this?

P.S - my pop up still doesn't work either, it just opens a new page with the form fields, but I assume that can be fixed later, the pop up doesn't matter to the actual functionality, right?