Jump to:

10843 Posts in 2514 Topics by 1792 members

All other Modules

SilverStripe Forums » All other Modules » [SOLVED] Controller does not hold correct Model!?!

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 622 Views
  • chrclaus
    Avatar
    Community Member
    29 Posts

    [SOLVED] Controller does not hold correct Model!?! Link to this post

    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

  • chrclaus
    Avatar
    Community Member
    29 Posts

    Re: [SOLVED] Controller does not hold correct Model!?! Link to this post

    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

    622 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.