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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Displaying Dataobjects in a list on the frontend


Go to End
Reply


3 Posts   873 Views

Avatar
slavelabourer

Community Member, 25 Posts

10 October 2011 at 11:28am

Hey guys, Having some trouble with a control block and complextablefield. Likely a n00b question but i'm at the point of wtf

$category in the template will display a list of entries but i want to show all the fields from $category. My first time using the complextablefield, so i'm pretty stuck on whats going wrong here.

cheers for you time

DriverHolder.php

<?php

class DriverHolder extends Page {
static $db = array(

);

static $has_one = array(

);
static $has_many = array(
'category' => 'category'
);

function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Drivers', new ComplexTableField(
$this,
'Title',
'category',
array('Title' => 'Title', 'Description' => 'Description'),
'getCMSFields_forPopup'
));

return $fields;

}
}

class DriverHolder_Controller extends Page_Controller {}

?>

DriverHolder.ss

<table>
<th>Driver</th><th>Description</th><th>Download</th>
<% control catagory %>
<tr>
<td>$Title</td>
<td>$Description</td>
<td>$File.URL</td>
</tr>
<% end_control %>
</table>

Avatar
JonoM

Community Member, 107 Posts

10 October 2011 at 3:25pm

You have a typo in your control block "catagory" - could be the cause?

Avatar
slavelabourer

Community Member, 25 Posts

10 October 2011 at 4:18pm

Yes i did, but i cleaned it up and still not working heres the cleaners version

driver.php

<?php
class driver extends DataObject {

	static $db = array (
		'Title' => 'Text',
		'Description' => 'Text'	
	);
		
	static $has_one = array (
		'DriverHolder' => 'DriverHolder',
		'File' => 'File' 	
	);
	
	static $has_many = array ();
	
	function getCMSFields_forPopup() {
		$fields = new FieldSet();
		$fields->push(new TextField('Title', 'Title'));
		$fields->push(new TextField('Description', 'Description'));
		$fields->push(new FileIFrameField('File', 'File'));
		
		return $fields;
	}
}

DriverHolder.php
<?php
class DriverHolder extends Page {
   static $db = array();
   
   static $has_one = array();
   
   static $has_many = array(
   	'driver' => 'driver'
   );
   
   static $allowed_children = array('DriverPage');   

   function getCMSFields() {
   	$fields = parent::getCMSFields();
   	$fields->addFieldToTab('Root.Content.drivers', new ComplexTableField(
   	                $this,
   	   		'Title', 
   	   		'driver', 
   	array('Title' => 'Title'),
   	   		'getCMSFields_forPopup'
   	));
   	return $fields;
   }
}
 
class DriverHolder_Controller extends Page_Controller {}

DriverHolder.ss
<table width="100%">
	<th>Driver</th><th>Description</th><th>Download</th>
		<% control driver %>
			<tr>
			        <td>$Title</td>
			        <td>$Description</td>
				<td><a href="$File.URL">[download]</a></td>
			</tr>
		<% end_control %>
	</table>