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've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Using DataObjectManager inside a DataObject Decorator


Go to End


5 Posts   2386 Views

Avatar
dospuntocero

Community Member, 54 Posts

4 December 2009 at 3:15am

Hi guys i was wondering why i can't use DataObjectManager inside a DataObjectDecorator... or why ComplexTableField works and DOM throws errors my code is fairly simple i think

I'm using decorators for my HomePage class so I can control stuff that are in all pages using in templates <% control Page(home) %> stuff.


in my _config: 	DataObject::add_extension('HomePage', 'LogoDecorator');

<?php

class LogoDecorator extends DataObjectDecorator{

	function extraStatics() {
		return array(
			'has_many' => array(
				'Logos' => 'Logo',
			),
		);
	}

	public function updateCMSFields(FieldSet &$fields) {
		$Banners = new ComplexTableField(
				$this,
				'Logos',
				'Logo',
				array(
					'TextoAlternativo' =>'TextoAlternativo',
					'Link' =>'Link'
				),
				'getCMSFields_forPopup'
		);
		$Banners->setParentClass('HomePage');	
		$fields->addFieldToTab( 'Root.Content.Logos', $Banners );		
	}	
}

and my logo class:

<?php

class Logo extends DataObject {

	static $db = array (
		'TextoAlternativo' => 'Varchar(140)',
		'Link' => 'Varchar(255)'
	);
	
	static $has_one = array (
		'HomePage' => 'HomePage',
		'Logo' => 'Image'
	);		
	public function getCMSFields_forPopup()
	{
		return new FieldSet(
			new TextareaField('TextoAlternativo', 'Texto Alternativo (para google) - máximo 140 caracteres'),
			new TextField("Link", "URL de la página de logo (sin http://)"),
			new ImageField('Logo', 'Agregar imagen para el banner')
		);
	}	
}

when i use DOM instead of ComplexTableField, the code just stop working... any clues?

thanks for all guys!

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 December 2009 at 3:45am

What does "stops working" mean? It's hard to troubleshoot something if you're not explaining the result.

Avatar
dospuntocero

Community Member, 54 Posts

4 December 2009 at 3:56am

well the error is a little bit large...

La página en http://sta dice:ERROR [Notice]: Undefined property: LogoDecorator::$ID
IN POST /admin/getitem?ID=5&ajax=1
Line 211 in /Users/francisco/Sites/stachile/dataobject_manager/code/DataObjectManager.php

Source
======
  202: 		$sort 	  = isset($params['sort'])? $params['sort'] 		    : 	$this->sort;
  203: 		$sort_dir = isset($params['sort_dir'])? $params['sort_dir'] : 	$this->sort_dir;
  204: 		$filter   = isset($params['filter'])? $params['filter'] 	  : 	$this->filter;
  205: 		$search   = isset($params['search'])? $params['search'] 	  : 	$this->search;
  206: 		return
       "ctf[{$this->Name()}][start]={$start}&ctf[{$this->Name()}][per_page]={$per_page}&ctf[{$this->Name()}][showall]={$show_all}&ctf[{$this->Name()}][sort]={$sort}&ctf[{$this->Name()}][sort_dir]={$sort_dir}&ctf[{$this->Name()}][search]={$search}&ctf[{$this->Name()}][filter]={$filter}";
  207: 	}
  208: 	
  209: 	function FieldHolder()
  210: 	{
* 211: 		if(!$this->controller->ID && $this->isNested)
  212: 			return $this->renderWith('DataObjectManager_holder');
  213: 		return parent::FieldHolder();
  214: 	}
  215: 
  216: 	
  217: 	public function Headings()

<ul>DataObjectManager->FieldHolder()

call_user_func_array(Array,Array)
line 408 of ViewableData.php

ViewableData->XML_val(FieldHolder,,1)
line 74 of .cache.Users.francisco.Sites.stachile.sapphire.templates.TabSetFieldHolder.ss

include(/private/var/tmp/silverstripe-cache-Users-francisco-Sites-stachile/.cache.Users.francisco.Sites.stachile.sapphire.templates.TabSetFieldHolder.ss)
line 354 of SSViewer.php

SSViewer->process(TabSet)
line 773 of ViewableData.php

ViewableData->renderWith(TabSetFieldHolder)
line 62 of TabSet.php

TabSet->FieldHolder()

call_user_func_array(Array,Array)
line 408 of ViewableData.php

ViewableData->XML_val(FieldHolder,,1)
line 59 of .cache.Users.francisco.Sites.stachile.sapphire.templates.TabSetFieldHolder.ss

include(/private/var/tmp/silverstripe-cache-Users-francisco-Sites-stachile/.cache.Users.francisco.Sites.stachile.sapphire.templates.TabSetFieldHolder.ss)
line 354 of SSViewer.php

SSViewer->process(TabSet)
line 773 of ViewableData.php

ViewableData->renderWith(TabSetFieldHolder)
line 62 of TabSet.php

TabSet->FieldHolder()

call_user_func_array(Array,Array)
line 408 of ViewableData.php

ViewableData->XML_val(FieldHolder,,1)
line 70 of .cache.Users.francisco.Sites.stachile.sapphire.templates.Includes.Form.ss

include(/private/var/tmp/silverstripe-cache-Users-francisco-Sites-stachile/.cache.Users.francisco.Sites.stachile.sapphire.templates.Includes.Form.ss)
line 354 of SSViewer.php

SSViewer->process(Form)
line 773 of ViewableData.php

ViewableData->renderWith(Array)
line 982 of Form.php

Form->forTemplate()
line 1005 of Form.php

Form->formHtmlContent()
line 381 of LeftAndMain.php

LeftAndMain->getitem(HTTPRequest)
line 162 of Controller.php

Controller->handleAction(HTTPRequest)
line 129 of RequestHandler.php

RequestHandler->handleRequest(HTTPRequest)
line 122 of Controller.php

Controller->handleRequest(HTTPRequest)
line 277 of Director.php

Director::handleRequest(HTTPRequest,Session)
line 121 of Director.php

Director::direct(/admin/getitem)
line 118 of main.php

</ul>

Avatar
UncleCheese

Forum Moderator, 4102 Posts

4 December 2009 at 4:20am

You're passing $this as the controller, which is the decorator. The controller you want is $this->owner.

Avatar
dospuntocero

Community Member, 54 Posts

4 December 2009 at 4:31am

woohooo!!

thanks UncleCheese!! :D now is working perfectly

:D:D:D