Hi,
I followed advices and how to's here about adding buttons and functions inside the cms. What i want to do is basically copy values from a set of dataojbects and create a new set of data objects using those values, as a duplication.
So i used getCMSactions. I set up in my page type a function like this
function getCMSActions(){
$actions = parent::getCMSActions();
$Action = new FormAction("doAction", "Import values");
$actions->push($Action);
return $actions;
}
Then I created a CMSActionDecorator.
<?php
class CMSActionDecorator extends LeftAndMainDecorator {
function doAction(){
$id = (int)$_REQUEST['ID'];
$thisPage = DataObject::get_one('MyPage', 'ID ='. $id);
$group = DataObject::get_one('MyPageGroup', 'ID =' . $thisPage->ParentID);
$generalvaluespage= DataObject::get_one('GeneralValuesPage', 'Name = ' .$group->Title);
$dataObjectToBeDuplicated = DataObject::get('DataObjectToBeDuplicated' , "CategoryID =". $generalvaluespage->ID);
foreach($dataObjectToBeDuplicated as $do){
$newDataObject = new MyDataObject;
$newDataObject->Value1 = $do->Value1;
$newDataObject->Value2 = $do->Value2;
$newDataObject->write();
}
FormResponse::status_message(sprintf('All good!'),'good');
return FormResponse::respond();
}
}
Then I added the extension line on _config as usual: Object::add_extension('CMSMain', 'CMSActionDecorator');
THis is not working. An error messagge inside the CMS says "SERVER ERROR". If i erase eveything except the request lines, it seems to be workin (no error messages, just the All Good green one). Anyone has clues?
I used this tutorial http://www.ssbits.com/adding-a-cms-action-the-slightly-hacky-way/
Thanks