Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

Moderators: martimiz, UncleCheese, Sean, Ed, biapar, Willr, Ingo, swaiba

best way


Go to End


3 Posts   603 Views

Avatar
servalman

Community Member, 211 Posts

13 June 2011 at 8:39pm

Hello

I have this project where I want to use dataobject and model admin :

I need to create a structure like this :

ITEM 1
ressource 1
ressource 2
ressource 3

ITEM 2
ressource 1
ressource 2
ressource 3

Every ressource level holds multiple files

For now I have created my ressource level
What I don't really get (I beggining with all this) is how I can go up one level and nest my ressources inside an ITEM

Here is my code so far (I guess that Ressource page will be ItemPage at the end)

code/ Resource.php:

<?php 
class Resource extends DataObject
{
	static $db = array (
		'Name' => 'Text',
		'Description' => 'Text',
	);
	
	static $has_one = array (
		'Attachment' => 'File',
		'ResourcePage' => 'ResourcePage'
	);
	
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextField('Name'),
			new TextareaField('Description'),
			new FileIFrameField('Attachment')
		);
	}
}
?>

also RessourceFile :

<?php

class ResourceFile extends File {

static $has_one = array (
'Resource' => 'Resource'
);
} 

and a RessourcePage.php

<?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'
			),
		);
		
		
				
		$f->addFieldToTab("Root.Content.Resources", $manager);

		return $f;
	}

}
class ResourcePage_Controller extends Page_Controller {


    }

}

I f someone could guide me to a tutorial or docs explaining me this a bit it would be great

Thanks

Avatar
UncleCheese

Forum Moderator, 4102 Posts

14 June 2011 at 2:10am

What is the purpose of ResourceFile?

Avatar
servalman

Community Member, 211 Posts

14 June 2011 at 2:34am

Hello Uncle Cheese

Ce fichier ne sert a rien (c'est l'une des nombreuse erreurs précédentes ;)

Une fois que j'aurais pu résoudre mon problème sur les autres fichier je vais essayer d'adpater l'exemple http://doc.silverstripe.org/sapphire/en/reference/modeladmin a mon cas.

Penses tu que cela soit une bonne solution ?

Merci