Jump to:

22997 Posts in 11853 Topics by 2828 members

General Questions

SilverStripe Forums » General Questions » ModelAdmin issues

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

Page: 1
Go to End
Author Topic: 1485 Views
  • mi3ll
    Avatar
    Community Member
    23 Posts

    ModelAdmin issues Link to this post

    Has anyone got the ModelAdmin code working in RC4? If so, I would be grateful if you can share your code or share what I am doing wrong, thanks.

    I've been having problems extending ModelAdmin in the RC4 and RC3 versions. It displays all right, but when I click the Create and Search buttons the ajax loading image fills the right hand screen and nothing happens (ajax error...)

    I checked the Error console in Firefox and it gives me this error:

    Too much recursion
    $('Form_CreateForm').validate is not a function

    I noticed that ModelAdmin loads both jquery and prototype, and the validation use $ function which they both use, so I'm thinking there must be a conflict? I'm not very good with javascript.

    Great application by the way!

    EDIT: If it helps, here is my other code:

    Stockist Dataobject

    <?php
    /**
    * Data representing a stockist
    */
    class Stockist extends DataObject {

    static $db = array(
    'Name' => 'Varchar',
    'Contact' => 'Varchar',
    'Address' => 'Text',
        'City' => 'Varchar',
        'Postcode' => 'Varchar',
        'Phone' => 'Varchar',
        'Fax' => 'Varchar',
        'Mobile' => 'Varchar',
        'Email' => 'Varchar',
        'Website' => 'Varchar',
        'FullStockist' => 'Boolean',
        'Date' => 'Date',
    );

    static $has_one = array(
    'Location' => 'Location'
    );

    static $searchable_fields = array(
    'Name' => array(
    'field' => 'TextField',
    'filter' => 'PartialMatchFilter',
    ),
    'Contact' => array(
    'field' => 'TextField',
    'filter' => 'PartialMatchFilter',
    ),
        'Address' => array(
    'field' => 'TextareaField',
    'filter' => 'PartialMatchFilter',
    ),
        'City' => array(
    'field' => 'TextField',
    'filter' => 'PartialMatchFilter',
    ),
        'Location.Name' => array(
           'title' => 'Location',
    'field' => 'TextField',
    'filter' => 'PartialMatchFilter',
    ),
        'Postcode' => array(
    'field' => 'NumericField',
           'filter' => 'ExactMatchFilter',
    ),
        'FullStockist' => array(
           'title' => 'Is a full stockist?',
    'field' => 'CheckboxField',
           'filter' => 'ExactMatchFilter',
    ),
        'Location.InAustralia' => array(
           'title' => 'Only in Australia?',
    'field' => 'CheckboxField',
           'filter' => 'ExactMatchFilter',
    )
    );

    static $summary_fields = array(
    'Name',
        'City',
    'Location.Name' => 'Location',
        'Phone',
        'FullStockist'
    );

    function getCMSFields() {
    // test
          $fields = new FieldSet();
          $fields->push(new TextField('Name', 'Business Name'));
          return $fields;
    }
    }

    ?>

    StockistAdmin.php

    <?php
    /**
    * Interface for maintaining stockists
    */
    class StockistAdmin extends ModelAdmin {

    protected static $managed_models = array(
    'Stockist',
    'Location'
    );

    static $url_segment = 'stockists';
    static $menu_title = 'Stockists';

    }

    ?>

    Inside my config file

    Director::addRules(50, array('admin/stockists/$Class/$Action/$ID' => 'StockistAdmin'));

  • Ben Gribaudo
    Avatar
    Community Member
    181 Posts

    Re: ModelAdmin issues Link to this post

    Hi mi3ll,

    Have you tried getting things working while using trunk? With the references to "Location" commented out (since I didn't have that model), the create button seemed to work fine on my system when I used a trunk checkout from yesterday.

    Also, I think the Director::addRules line is unnecessary with the current version of ModelAdmin.

    Hope this helps a little,
    Ben

  • mi3ll
    Avatar
    Community Member
    23 Posts

    Re: ModelAdmin issues Link to this post

    Hi bgribaudo,

    Thanks for replying! Yes, using the daily build from 17-02-2009 worked! Of course the answer was so simple...

    Thanks for telling me about that line, I tried using ModelAdmin in RC4 and it would not work without that line for me (I mean, adding this line produced more closely the results I wanted, but didn't really work xD)

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: ModelAdmin issues Link to this post

    I seem to be having the same problem in the final release 2.3.0.

    Would you mind trying your code in the final release ?

  • Fuzz10
    Avatar
    Community Member
    786 Posts

    Re: ModelAdmin issues Link to this post

    Ah.. my problem was solved by removing HTMLFields in the dataobject. ModelAdmin doesn't like those. ;)

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