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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

ModelAsController::getNestedController() returned bad object type


Reply


4 Posts   3117 Views

Avatar
Tesla

Community Member, 9 Posts

20 August 2010 at 8:05am

I'm not sure this is a DataObjectManager problem, but I have been struggling with this for a week now and can't find a solution.

I am building a video gallery for a site i'm working on and I keep getting this error when I view the live page on the site. The strange thing is it was working at first and now, nothing.

[User Warning] ModelAsController::getNestedController() returned bad object type 'VideoPage'
GET /gc/video/

Line 70 in C:\xampp\htdocs\gc\sapphire\core\control\ModelAsController.php

Source

61       }
62       
63       try {
64          $result = $this->getNestedController();
65          
66          if($result instanceof RequestHandler) {
67             $result = $result->handleRequest($this->request);
68          } else if(!($result instanceof SS_HTTPResponse)) {
69             user_error("ModelAsController::getNestedController() returned bad object type '" .
70                get_class($result)."'", E_USER_WARNING);
71          }
72       } catch(SS_HTTPResponse_Exception $responseException) {
73          $result = $responseException->getResponse();
74       }
75       
76       $this->popCurrent();
Trace

ModelAsController::getNestedController() returned bad object type 'VideoPage'
Line 70 of ModelAsController.php
ModelAsController->handleRequest(SS_HTTPRequest)
Line 283 of Director.php
Director::handleRequest(SS_HTTPRequest,Session)
Line 127 of Director.php
Director::direct(/video/)
Line 127 of main.php

Here is my code.

Video.php

class Video extends DataObject {
   
   static $db = array (
      'Title' => 'Text',
      'Date' => 'Date',
      'AddedBy' => 'Text',
      'Category' => 'Text',
      'Description' => 'Text',
      'VideoShortCode' => 'HTMLText'
   );
   
   static $has_one = array (
      'VideoPage' => 'VideoPage'
   );
      
   public function getCMSFields_forPopup()
   {
      return new FieldSet(
         new TextField('Title'),
         new DatePickerField('Date'),
         new TextField('AddedBy'),
         new TextField('Category'),
         new TextareaField('Description'),
         new TextField('VideoShortCode')
      );
   }
}

VideoPage.php

class VideoPage extends Page {

   static $icon = "video_gallery/images/vidicon";
   
   static $db = array (
      'VideoWidth' => 'Int',
      'VideoHeight' => 'Int'
   );
   static $has_many = array (
      'Videos' => 'Video'
   );
   
   static $defaults = array (
      'VideoWidth' => '320',
      'VideoHeight' => '210'
   );
   
   public function getCMSFields()
   {
      $f = parent::getCMSFields();
      $f->addFieldToTab("Root.Content.Videos", new DataObjectManager(
         $this,
         'Videos',
         'Video',
         array('Title' => 'Title','Date' => 'Date','AddedBy'=>'AddedBy','Category'=>'Category','Description' => 'Description','VideoShortCode' => 'VideoShortCode'),
         'getCMSFields_forPopup'
      ));
      $f->addFieldToTab("Root.Content.Configuration", new HeaderField($title = ('Defaults'), $headingLevel = "3"));
      $f->addFieldToTab('Root.Content.Configuration', new NumericField('VideoWidth','Video Width'));
      $f->addFieldToTab('Root.Content.Configuration', new NumericField('VideoHeight','Video Height'));
      return $f;
   }
}

And here is the template I'm using.

   <% if Videos %>
      <% control Videos %>
         <div id="video-list">
            <table width="600" border="0" cellpadding="0" cellspacing="0">
               <tr>
                  <td colspan="2"><div id="video-list_title">$Title</div></td>
               </tr>
               <tr>
                  <td><div id="video-list_subtitle">Added By: $AddedBy on $Date</div></td>
                  <td rowspan="2"><div id="video-list_window">$VideoShortCode</td>
               </tr>
               <tr>
                  <td valign="top"><div id="video-list_description">$Description</div></td>
               </tr>
            </table>      
         </div>
      <% end_control %>
   <% end_if %>

I have tried everything I can think of and I still get the error. Any help would be appreciated.

Avatar
hornergraphic

Community Member, 4 Posts

30 October 2010 at 4:24am

Hi Tesla,

I'm guessing this response is a couple of months too late(!) for you but for others searching this error on the forum I thought I would post the solution.

Your VideoPage.php file must extend the Page_Controller class as well. So your file should look like:

class VideoPage extends Page {

   ...
   ...
   ...

}

class VideoPage_Controller extends Page_Controller {
   
   public static $allowed_actions = array (
   );

   public function init() {
      parent::init();
   }
}

I inadvertently created the same problem when I removed my file and Page class and forgot to rename the controller class.

Avatar
Mrfixer

Community Member, 49 Posts

4 February 2011 at 12:47pm

Thanks hornergraphic, thats just helped me out heaps.. i was thinking an uninstall was on the cards..

Avatar
AshKyd

Community Member, 1 Post

31 March 2013 at 10:33pm

As an FYI, this can also occur if you haven't specified a controller, or you've accidentally renamed the controller to something different.