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

DataObjectManager Code Examples for the Frontend


Go to End


6 Posts   1998 Views

Avatar
cardinale

Community Member, 23 Posts

27 March 2010 at 2:11am

Edited: 27/03/2010 2:14am

Hallo,
I'm looking for an Code Example to integrate DOM in the Frondend.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

27 March 2010 at 2:51am

I don't know that it will work, but you can give it a try. The only difference between a CMS form and a frontend form is that you can't pass the controller as $this. You'll have to pass it an instance of the holder object for the records you're managing. But there are a lot of other things to consider like javascript dependencies that will probably trip it up.

It's definitely in my plans to make a frontend safe DOM, though.

Avatar
cardinale

Community Member, 23 Posts

27 March 2010 at 3:01am

I tried it like this:

public function NachrichtenField() {

$AerzteTable = new DataObjectManager(
$this,
'Testimonials',
'Nachricht',
array('ID' => 'ID'),
null
);
$AerzteTable->setPermissions(array());
$AerzteTable->setCustomSourceItems($this->Nachrichten);

$Felder = new FieldSet( $AerzteTable );
$Action = new FieldSet(new FormAction("Weiterleitung", 'hallo', 'Modifica Informazioni Utente - Indirizzo commerciale') );
return new Form($this, "NacchrichtenField", $Felder, $Action);
}

But I want only a nice table, without other formelemements like the submit button.
- The "Show results per page" doesn't work
- The "Search" doesn't work

Avatar
UncleCheese

Forum Moderator, 4102 Posts

27 March 2010 at 3:41am

What is $this in that function?

Avatar
cardinale

Community Member, 23 Posts

27 March 2010 at 4:10am

here the code, I put $this just because i don't know what to put else. is there a way to get working the search function or to switch it off?

<?php
class NachrichtenPage extends Page {

public function getNachrichten() {
$MemberID = Member::currentUserID();
$auslese = DataObject::get('Nachricht', 'DepositaerID = "'.$MemberID.'" AND (Status = "NEU" OR Status = "GELESEN")' );
return $auslese;
}

}

class NachrichtenPage_Controller extends Page_Controller {

public function NachrichtenField() {

$AerzteTable = new DataObjectManager(
$this,
'Testimonials',
'Nachricht',
array('ID' => 'ID', 'Created' => 'Datum','Title'=> 'Betreff', 'Status' => 'Status',),
null
);
$AerzteTable->setPermissions(array());
$AerzteTable->setCustomSourceItems($this->Nachrichten);
$AerzteTable->per_page_map = array('10');
$AerzteTable->use_view_all = false;

$Felder = new FieldSet( $AerzteTable );
$Action = new FieldSet(new FormAction($this, 'hallo') );
$myForm = new Form($this, "NacchrichtenField", $Felder, $Action);
$myForm->getValidator()->setJavascriptValidationHandler('none');
return $myForm;
}

}

?>

Avatar
MarijnKampf

Community Member, 176 Posts

31 March 2010 at 3:12am

Edited: 31/03/2010 3:13am

I've been looking into this too, and I've had some luck generating something that works, but it isn't perfect.

@cardinale: you could try DataObject::get('Nachricht', 'DepositaerID = "'.$MemberID.'" AND (Status = "NEU" OR Status = "GELESEN")' ); or possibly $this->getNachtrighten() instead of $this.

@UncleCheese: It works somewhat for DataObjects, if I try to include objects based on SiteTree I get the error:

	public function ProjectsTable() {
// Works
		$table = new DataObjectManager(DataObject::get("Source"), "Sources", "Source", array('Title' => 'Title'), "getCMSFields_forPopup");
// Fails with error
//		$projects = DataObject::get("Page");
//		$table = new DataObjectManager($projects, "Pages", "Page", array('Title' => 'Title'), "getCMSFields_forPopup");
    $table->setPermissions(array());

		$fields = new FieldSet( $table );
		$Action = new FieldSet(new HiddenField($this, 'No button') );
		$myForm = new Form($this, "ProjectsTable", $fields, $Action);
		$myForm->getValidator()->setJavascriptValidationHandler('none');
		return $myForm;
	}

[User Error] Couldn't run query: SELECT COUNT(DISTINCT SiteTree.ID) AS TotalCount FROM `SiteTree_Live` LEFT JOIN `Page_Live` ON `Page_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `BlogEntry_Live` ON `BlogEntry_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `BlogHolder_Live` ON `BlogHolder_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `DonationPage_Live` ON `DonationPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `ContactPage_Live` ON `ContactPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `Expert_Live` ON `Expert_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `FeaturedPage_Live` ON `FeaturedPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `Project_Live` ON `Project_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `Region_Live` ON `Region_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `Species_Live` ON `Species_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `ErrorPage_Live` ON `ErrorPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `RedirectorPage_Live` ON `RedirectorPage_Live`.ID = `SiteTree_Live`.ID LEFT JOIN `VirtualPage_Live` ON `VirtualPage_Live`.ID = `SiteTree_Live`.ID WHERE (`SiteTree_Live`.ClassName IN ('Page','BlogEntry','BlogHolder','DonationPage','ContactPage','CountriesHolder','Expert','ExpertsHolder','Family','FeaturedHolder','FeaturedPage','Project','ProjectDOM','ProjectsHolder','Region','RegionsHolder','Species','TestimonialPage','ErrorPage','RedirectorPage','VirtualPage','AgendaHolder')) Unknown column 'SiteTree.ID' in 'field list'
GET /largeherbivore.org/new-projectdom?stage=LIVE

Line 401 in G:\localhost\largeherbivore.org\sapphire\core\model\MySQLDatabase.php

It looks to me that the FROM table isn't passed the Live / staging attribute as the error doesn't occur when I look at the staging site. Clicking on the labels in the table didn't sort the column but resulted in a blank pages featuring the text 'mysite'.