Jump to:

23471 Posts in 18941 Topics by 2878 members

General Questions

SilverStripe Forums » General Questions » New Module to Create/Edit/Delete DataObject rows in CMS (ss v2.2.2)

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: 1922 Views
  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    New Module to Create/Edit/Delete DataObject rows in CMS (ss v2.2.2) Link to this post

    Hi,

    I am trying to get a simple new Module into the CMS (to edit several tables of data, maybe more in the future). I have been reading the example in the silverstripe book and I would like to create something very similar (with as little code as possible) to maintain the data in several reference tables. I'd like to be using ModelAdmin, but due to 2.2.2 I think using GenericDataAdmin is the best option.

    At the moment I have a new DataObject called PromoCodes and a module called myadmin. The CMS display the new module in the top menu bar... but the left and right main sections are not close to my desire yet. Currently the left area shows a search form that when submitted shows the results, but not into the right area. And the right area shows the contents of the table (SELECT * FROM) but when a record is clicked it just refresehs the screen.

    The left area I would like (if you have the book I am looking at 6.3 Using ModelAdmin for Data Management) to show this table/dataobject as part of a list or one of a set of tabs. Then selecting that table updates the right side with the 'search results' (select from table), then from this view a row could be viewed, editted or deleted. In the case of a view/edit I would like to have the right area become a single generic record editor. This is a wish, but anything that would accomplish maintaining this required data in the simplist code possible would be greatly appreciated.

    I have included my current code and ask very politely if someone could please help me with this

    mysite/code/PromoCodes.php

    class PromoCodes extends DataObject
    {
       static $db = array(
          'ID' => 'Int',
          'PromoCode' => 'Text',
          'ExipryDate' => 'Date',
          'IsLimted' => 'Boolean',
          'Limit' => 'Int',
          'Type' => "Enum(array('Percent', 'Fixed Value'))",
          'DiscountAmount' => 'Int'
       );
    }

    myadmin/_config.php

    Object::addStaticVars('LeftAndMain', array('extra_menu_items' => array('Admin' => 'admin/myadmin/')));
    Director::addRules(100, array('admin/myadmin/$Action/$ID' => 'MyAdmin'));

    myadmin/code/MyAdmin.php

    class MyAdmin extends GenericDataAdmin
    {
       public static $data_type = 'PromoCodes';
       
       public static $result_columns = array('Promotional Code' => 'PromoCode',
                         'Exipry Date' => 'ExipryDate',
                         'Is Limted?' => 'IsLimted',
                         'Limit' => 'Limit',
                         'Type' => 'Type',
                         'Discount Amount' => 'DiscountAmount');
       
       function performSearch()
       {
          return DataObject::get('PromoCodes');
       }
       
       function getSearchFields()
       {
          return new FieldSet(
             new TextField('PromoCode', "PromoCode", "test"),
             new CurrencyField('ExipryDate', "ExipryDate", "test")
          );
       }
       
       function getLink()
       {
          if (!isset($action))
             $action="";
          return "admin/myadmin/$action";
       }
    }

    myadmin/templates/MyAdmin_right.ss

    <% if EditForm %>
       $EditForm
    <% else %>
       $Results
    <% end_if %>

    <p id="statusMessage" style="visibility:hidden"></p>

    myadmin/templates/MyAdmin_left.ss

    <h2>Admin</h2>
    <div id="treepanes" style="overflow-y: auto;">
          <div id="sitetree_holder">   
             <div id="sitetree_ul">
                $SearchForm
             </div>
          </div>
    </div>

  • swaiba
    Avatar
    Forum Moderator
    1792 Posts

    Re: New Module to Create/Edit/Delete DataObject rows in CMS (ss v2.2.2) Link to this post

    Hello again,

    Sorry to hassle you nice folks, but I could really use some help here please.

    I would upgrade if my predecessor had not customized the 'core' code so much.

    Any help on how to add a module in 2.2.2 that will simply edit refernce data in DataObjects (that have already been created and all the site related functionality is there) would be very much appreciated - I've been on this for two days and it seems ridicuslous that it is so difficult.

    Barry

  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    Re: New Module to Create/Edit/Delete DataObject rows in CMS (ss v2.2.2) Link to this post

    Hi Barry

    There are a couple of options

    * use the standard form functionality and build something custom (should take only a few hours).
    * integrate modeladmin into your version (might be a nightmare, but worth a try)
    * debug your current code into something that works

    Between those three options I am sure there is hope ;-)

    Best option: UPGRADE!

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