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.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

All other Modules /

Discuss all other Modules here.

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

[SOLVED] Controller does not hold correct Model!?!


Go to End


2 Posts   909 Views

Avatar
chrclaus

Community Member, 29 Posts

12 August 2010 at 9:11pm

Edited: 13/08/2010 12:04am

Hello,

I created a new page MyNewPage by extending UserDefinedForm and created the controller (extending UserDefinedForm_Controller) too. The page itself contains getter-methods to access the db-fields. A new site in CMS was created.

By sending an AJAX-Request, handled in the controller, I want to access this getter-method by

$this->data()->myGetter();

I got an error message "Object->__call(): the method 'myGetter' does not exist on 'Page'. I am wondering about the resulting type of $this->data() beeing type Page. I expected the page type MyNewPage.
By investigating the situation, I found a code snippet in the constructor of ContentController. At this point (line 41 in v2.4.1), the class-variable $dataRecord is set = new Page(); if the dataRecord was not given as parameter. I don´t understand this relation, why $dataRecord is not set to the correct model-instance of MyNewPage.

I think, the problem is related to the AJAX-url, with which the determination of a concrete instance is not possible. Is the only solution to determine the dataObject by myself in handling the AJAX-Request?

Best regards,
chrclaus

Avatar
chrclaus

Community Member, 29 Posts

13 August 2010 at 12:03am

Hello,

I found the problem by myself - sometimes it´s a good idea to write a problem down to a paper to get a different point of view ;-).

The problem is the url, specified in the AJAX-request. I used the url MyNewPage_Controller/action with which it is not possible to determine a concrete dataobject. After switching to the page-link /mysites/mynewpage/action the underlying data-model is set correctly.

Best regards,
chrclaus