title: Silverstripe Model Admin for Pages
body: <p>I am using the Silverstripe Swipestripe module for an online store. Because of the number of products the client has, it's not practical to nave them navigate to each individual product through the site tree when they want to make changes to a product (which happens fairly regularly) so I'd like to have a modeladmin to list all products and allow them to search for a product by name/stockcode.</p>
  
  <p>I thought this would be solvable in the same way as DataObjects (and searches seem to suggest that people have done achieved this), however when I navigate to products in ModelAdmin view, I get:</p>
  
  <blockquote>
    <p>Fatal Error :  Call to a member function stat() on a non-object in
    /path/to/folder/wwwroot/framework/model/DataObject.php on line 3192</p>
  </blockquote>
  
  <pre><code>&lt;?php
  class ProductAdmin extends ModelAdmin
  { 
      private static $managed_models = array('Product'); 
      private static $url_segment = 'product'; 
      private $menu_title = 'Products';
  
  }
  </code></pre>
  
  <p>Interestingly, pages and other extensions of the page class do work.</p>
  
  <p>Here is the code for the Product class:</p>
  
  <pre><code>class Product extends Page {
  
      /**
       * Flag for denoting if this is the first time this Product is being written.
       * 
       * @var Boolean
       */
      protected $firstWrite = false;
  
      /**
       * DB fields for Product.
       * 
       * @var Array
       */
      private static $db = array(
          'Price'     =&gt; 'Decimal(19,4)',
          'Currency'  =&gt; 'Varchar(3)',
          'StockCode' =&gt; 'Varchar(255)',
          'Stock'     =&gt; 'Int',
          'Featured'  =&gt; 'Boolean',
          'YouTubeID' =&gt; 'Varchar(255)'
  
      );
  
      /**
       * Actual price in base currency, can decorate to apply discounts etc.
       * 
       * @return Price
       */
      public function Amount() {
  
          // TODO: Multi currency
          $shopConfig = ShopConfig::current_shop_config();
  
          $amount = new Price();
          $amount-&gt;setAmount($this-&gt;Price);
          $amount-&gt;setCurrency($shopConfig-&gt;BaseCurrency);
          $amount-&gt;setSymbol($shopConfig-&gt;BaseCurrencySymbol);
  
          //Transform amount for applying discounts etc.
          $this-&gt;extend('updateAmount', $amount);
  
          return $amount;
      }
  
      /**
       * Display price, can decorate for multiple currency etc.
       * 
       * @return Price
       */
      public function Price() {
  
          $amount = $this-&gt;Amount();
  
          //Transform price here for display in different currencies etc.
          $this-&gt;extend('updatePrice', $amount);
  
          return $amount;
      }
  
      /**
       * Has many relations for Product.
       * 
       * @var Array
       */
      private static $has_many = array(
          'Attributes' =&gt; 'Attribute',
          'Options' =&gt; 'Option',
          'Variations' =&gt; 'Variation'
      );
  
      /**
       * Defaults for Product
       * 
       * @var Array
       */
      private static $defaults = array(
          'ParentID' =&gt; -1,
          'Stock'     =&gt; 999
      );
  
      /**
       * Summary fields for displaying Products in the CMS
       * 
       * @var Array
       */
      private static $summary_fields = array(
          'Amount.Nice' =&gt; 'Price',
          'Title' =&gt; 'Title'
      );
  
      private static $searchable_fields = array(
          'Title' =&gt; array(
              'field' =&gt; 'TextField',
              'filter' =&gt; 'PartialMatchFilter',
              'title' =&gt; 'Name'
          )
      );
  
      /**
       * Set firstWrite flag if this is the first time this Product is written.
       * 
       * @see SiteTree::onBeforeWrite()
       * @see Product::onAfterWrite()
       */
      public function onBeforeWrite() {
          parent::onBeforeWrite();
          if (!$this-&gt;ID) $this-&gt;firstWrite = true;
  
          //Save in base currency
          $shopConfig = ShopConfig::current_shop_config();
          $this-&gt;Currency = $shopConfig-&gt;BaseCurrency;
      }
  
      /**
       * Unpublish products if they get deleted, such as in product admin area
       * 
       * @see SiteTree::onAfterDelete()
       */
      public function onAfterDelete() {
          parent::onAfterDelete();
  
          if ($this-&gt;isPublished()) {
              $this-&gt;doUnpublish();
          }
      }
  
      /**
       * Set some CMS fields for managing Products
       * 
       * @see Page::getCMSFields()
       * @return FieldList
       */
      public function getCMSFields() {
  
          $shopConfig = ShopConfig::current_shop_config();
          $fields = parent::getCMSFields();
  
          //Product fields
          $fields-&gt;addFieldToTab('Root.Main', new PriceField('Price'), 'Content');
          $fields-&gt;addFieldToTab('Root.Main', new TextField('StockCode'), 'Price');
          $fields-&gt;addFieldToTab('Root.Main', new TextField('Stock'), 'Price');
          $fields-&gt;addFieldToTab('Root.Main', new CheckBoxField('Featured'), 'Content');
          $fields-&gt;addFieldToTab('Root.Images', new TextField('YouTubeID', 'YouTube Video ID (Taken from the end of the video url. ie https://www.youtube.com/watch?v=ABC123 would be ABC123)'));
  
          //Replace URL Segment field
          if ($this-&gt;ParentID == -1) {
              $urlsegment = new SiteTreeURLSegmentField("URLSegment", 'URLSegment');
              $baseLink = Controller::join_links(Director::absoluteBaseURL(), 'product/');
              $url = (strlen($baseLink) &gt; 36) ? "..." .substr($baseLink, -32) : $baseLink;
              $urlsegment-&gt;setURLPrefix($url);
              $fields-&gt;replaceField('URLSegment', $urlsegment);
          }
  
          if ($this-&gt;isInDB()) {
  
              //Product attributes
              $listField = new GridField(
                  'Attributes',
                  'Attributes',
                  $this-&gt;Attributes(),
                  GridFieldConfig_BasicSortable::create()
              );
              $fields-&gt;addFieldToTab('Root.Attributes', $listField);
  
              //Product variations
              $attributes = $this-&gt;Attributes();
              if ($attributes &amp;&amp; $attributes-&gt;exists()) {
  
                  //Remove the stock level field if there are variations, each variation has a stock field
                  $fields-&gt;removeByName('Stock');
  
                  $variationFieldList = array();
                  foreach ($attributes as $attribute) {
                      $variationFieldList['AttributeValue_'.$attribute-&gt;ID] = $attribute-&gt;Title;
                  }
                  $variationFieldList = array_merge($variationFieldList, singleton('Variation')-&gt;summaryFields());
  
                  $config = GridFieldConfig_HasManyRelationEditor::create();
                  $dataColumns = $config-&gt;getComponentByType('GridFieldDataColumns');
                  $dataColumns-&gt;setDisplayFields($variationFieldList);
  
                  $listField = new GridField(
                      'Variations',
                      'Variations',
                      $this-&gt;Variations(),
                      $config
                  );
                  $fields-&gt;addFieldToTab('Root.Variations', $listField);
              }
          }
  
          //Ability to edit fields added to CMS here
          $this-&gt;extend('updateProductCMSFields', $fields);
  
          if ($warning = ShopConfig::base_currency_warning()) {
              $fields-&gt;addFieldToTab('Root.Main', new LiteralField('BaseCurrencyWarning', 
                  '&lt;p class="message warning"&gt;'.$warning.'&lt;/p&gt;'
              ), 'Title');
          }
  
          return $fields;
      }
  
      /**
       * Get the URL for this Product, products that are not part of the SiteTree are 
       * displayed by the {@link Product_Controller}.
       * 
       * @see SiteTree::Link()
       * @see Product_Controller::show()
       * @return String
       */
      public function Link($action = null) {
  
          if ($this-&gt;ParentID &gt; -1) {
              return parent::Link($action);
          }
          return Controller::join_links(Director::baseURL() . 'product/', $this-&gt;RelativeLink($action));
      }
  
      /**
       * A product is required to be added to a cart with a variation if it has attributes.
       * A product with attributes needs to have some enabled {@link Variation}s
       * 
       * @return Boolean
       */
      public function requiresVariation() {
          $attributes = $this-&gt;Attributes();
          return $attributes &amp;&amp; $attributes-&gt;exists();
      }
  
      /**
       * Get options for an Attribute of this Product.
       * 
       * @param Int $attributeID
       * @return ArrayList
       */
      public function getOptionsForAttribute($attributeID) {
  
          $options = new ArrayList();
          $variations = $this-&gt;Variations();
  
          if ($variations &amp;&amp; $variations-&gt;exists()) foreach ($variations as $variation) {
  
              if ($variation-&gt;isEnabled()) {
                  $option = $variation-&gt;getOptionForAttribute($attributeID);
                  if ($option) $options-&gt;push($option); 
              }
          }
          $options = $options-&gt;sort('SortOrder');
          return $options;
      }
  
      /**
       * Validate the Product before it is saved in {@link ShopAdmin}.
       * 
       * @see DataObject::validate()
       * @return ValidationResult
       */
      public function validate() {
  
          $result = new ValidationResult(); 
  
          //If this is being published, check that enabled variations exist if they are required
          $request = Controller::curr()-&gt;getRequest();
          $publishing = ($request &amp;&amp; $request-&gt;getVar('action_publish')) ? true : false;
  
          if ($publishing &amp;&amp; $this-&gt;requiresVariation()) {
  
              $variations = $this-&gt;Variations();
  
              if (!in_array('Enabled', $variations-&gt;map('ID', 'Status')-&gt;toArray())) {
                  $result-&gt;error(
                      'Cannot publish product when no variations are enabled. Please enable some product variations and try again.',
                      'VariationsDisabledError'
                  );
              }
          }
          return $result;
      }
  
  }
  </code></pre>
  
  <p>Can anyone suggest what I'm doing wrong here or an alternative way to do what I'm trying to achieve?</p>
  
  <p>Cheers</p>