Uncle cheese I have changed page with no luck nothing is happening with regards to sorting the datasheets I have into categories.
Here is the code may help??
All the objects are working fine just no Category sorting or title.
----------------
ResourcePage.php
---------------
class ResourcePage extends Page
{
static $has_many = array (
'Resources' => 'Resource'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new FileDataObjectManager(
$this, // Controller
'Resources', // Source name
'Resource', // Source class
'Attachment', // File name on DataObject
array(
'Name' => 'Name',
'Description' => 'Description',
'Category' => 'Category'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
$manager->setFilter(
'Category', // Name of field to filter
'Filter by Category', // Label for filter
singleton('Resource')->dbObject('Category')->enumValues() // Map for filter (could be $dataObject->toDropdownMap(), e.g.)
);
// If undefined, all types are allowed. Pass with or without a leading "."
$manager->setAllowedFileTypes(array('pdf','doc'));
// Label for the upload button in the popup
$manager->setBrowseButtonText("Upload (PDF or DOC only)");
// In grid view, what field will appear underneath the icon. If left out, it defaults to the file title.
$manager->setGridLabelField('Name');
// Plural form of the objects being managed. Used on the "Add" button.
// If left out, this defaults to [MyObjectName]s
$manager->setPluralTitle('Resources');
$f->addFieldToTab("Root.Content.Resources", $manager);
return $f;
}
function MyFileObjects()
{
$filter = Director::urlParam('Action');
return $filter ? $this->Resources("Category = '$filter'") : $this->Resources();
}
}
class ResourcePage_Controller extends Page_Controller
{
function category()
{
$resources = DataObject::get("Resource","Category='".$this->urlParams['ID']."'");
if($resources) {
return $this->customise(array(
'Resources' => $resources,
'CategoryTitle' => $this->urlParams['ID']
));
}
return false;
}
}
-----------------
Resource.php
----------------
class Resource extends DataObject
{
static $db = array (
'Name' => 'Text',
'Description' => 'Text',
'Category' => "Enum('CSO Storage Solutions, Storm Water Storage Solutions, Highways Applications, Surface Water & Sewage Pipelines, Water Treatment Works, Drinking Water, Renewable Energy, ATS Applications, Litespeed Applications')"
);
static $has_one = array (
'Attachment' => 'File',
'ResourcePage' => 'ResourcePage'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new TextareaField('Description'),
new DropdownField('Category','Category', singleton('Resource')->dbObject('Category')->enumValues()),
new FileIFrameField('Attachment')
);
}
}
--------------
ResourcePage.ss
--------------
<% if Resources %>
<% control Resources %> $CategoryTitle
<ul>
<li><a href="$Attachment.URL">$Name</a><br>$Description</li>
</ul>
<% end_control %>
<% end_if %>