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

How to call action from dataobject


Go to End


16 Posts   3029 Views

Avatar
Webdoc

Community Member, 349 Posts

17 November 2010 at 3:56am

Lets say that i have one page where is lot of sample models like bikes and so on they have all the same dataobject they are using lets say (bike).

But there are lot of bike types like Supermoto, Street, Ebduro and so on. what i need to add in dataobject bike so i can tel the object in what product row it needs to be in holderpage of bikes

Example using this thing: http://www.bmw.ee/Mudelivalik-34173cb38f07f89ddbebc2ac9128303f

this is URL of holder page how it must be

I understand that i need to add something like they are using in ecommerce for featuerd product or some enum field but lets say that i add enum field and in dataobject i choose what enum that or the other bike is but how to show them like so how to call the action to but the models to right row

Avatar
UncleCheese

Forum Moderator, 4102 Posts

17 November 2010 at 4:28am

You wouldn't define that in the model. That's something that belongs in the controller for that holder page.

Where are the categories defined in your model?

Avatar
Webdoc

Community Member, 349 Posts

17 November 2010 at 5:01am

nop i think i set them in my dataobject bike.php and use enum but how can i show them in the bike.ss so as they are in the website.
not bike_show.ss

if i add the enum i chooce some catecory from dropdown in dataobject and save it. but how can i make the ss to show them in right place like div called supermoto has all the bikes i have set supermoto. and so on.

Avatar
Webdoc

Community Member, 349 Posts

17 November 2010 at 5:10am

Edited: 17/11/2010 5:11am

for example if i use in my data object:
static $db = array(
'BikeCategory' => "Enum('Enduro,Sport,tour')"
);

and it gives me the drop down in my dataobject how i call it to frontend to show me all the bikes choosed enduro are in enduro row and so on.

what action i need to place in my pagetype bikelist.php and what is needed for bike.ss to show them

Avatar
UncleCheese

Forum Moderator, 4102 Posts

17 November 2010 at 5:34am

Edited: 17/11/2010 5:35am

Here's some pseudo code..

public function Categories() {
$ret = new DataObjectSet();
foreach(singleton('Bike')->dbObject('BikeCategory')->enumValues() as $cat) {
$ret->push(new ArrayData(array(
'CategoryName' => $cat,
'Bikes' => DataObject::get("Bike","BikeCategory = '$cat'")
)));
}
}

<% control Categories %>
$CategoryName
<% control Bikes %>
$BikeField1 $BikeField2
<% end_control %>
<% end_control %>

Avatar
Webdoc

Community Member, 349 Posts

19 November 2010 at 1:32am

Didnt work i write u may code maybe u can tell whats wrong!

Mootorrattas.php

<?php
class Mootorrattas extends DataObject
{
	static $db = array (
	'MootorrattaCategory' => "Enum('Enduro,Sport,Tour,Racing')",
	'Mootorrattanimi' => 'Text', 
	'Kirjeldus' => 'HTMLText',
	'Mootor' => 'Text',
	'Mootorivoimsus' => 'Text',
	'Poordemoment' => 'Text',
	'Surveaste' => 'Text',
	'Kytusesisselase' => 'Text',
	'Tippkiirus' => 'Text',
	'Sidur' => 'Text',
	'Kaivitussysteem' => 'Text',
	'Kaigukast' => 'Text',
	'Amordid' => 'Text',
	'Pidurid' => 'Text',
	'Rattad' => 'Text',
	'Istmekorgus' => 'Text',
	'Bensiinipaak' => 'Text',
	'Tyhimass' => 'Text',
	'Varvid' => 'Text',
	'Garantii' => 'Text',
	'Muuinfo' => 'Text',
	'Hind' => 'Text',
	'Soodushind' => 'Text',
	'Tahelepanu' => 'HTMLText',
	); 
	static $has_one = array ( 
	'Mootorrattalist' => 'Mootorrattalist',
	'Photo' => 'Image'
	); 
	static $has_many = array (
	'MootorrattasGalleryImages' => 'MootorrattasGalleryImage' 
	);
	public function getCMSFields_forPopup()
	{
	return new FieldSet(
		new DropdownField('MootorrattaCategory','MootorrattaCategory',singleton('Mootorrattas')->dbObject('MootorrattaCategory')->enumValues()),
		new TextField('Mootorrattanimi', 'Mootorratta nimi'),
		new SimpleWysiwygField('Kirjeldus', 'Mootorratta kirjeldus'),
		new TextField('Mootor', 'Mootor'),
		new TextField('Mootorivoimsus', 'Mootori v&otilde;imsus'),
		new TextField('Poordemoment', 'P&ouml;&ouml;rdemoment'),
		new TextField('Surveaste', 'Surveaste'),
		new TextField('Kytusesisselase', 'K&uuml;tuse sisselase'),
		new TextField('Tippkiirus', 'Tippkiirus'),
		new TextField('Kaivitussysteem', 'K&auml;ivituss&uuml;steem'),
		new TextField('Sidur', 'Sidur'),
		new TextField('Kaigukast', 'K&auml;igukast'),
		new TextField('Amordid', 'Amordid'),
		new TextField('Pidurid', 'Pidurid'),
		new TextField('Rattad', 'Rattad'),
		new TextField('Istmekorgus', 'Istmek&otilde;rgus'),
		new TextField('Bensiinipaak', 'Bensiinipaak'),
		new TextField('Tyhimass', 'T&uuml;himass'),
		new TextField('Varvid', 'V&auml;rvid'),
		new TextField('Garantii', 'Garantii'),
		new TextField('Muuinfo', 'Muu info'),
		new TextField('Hind', 'Hind'),
		new TextField('Soodushind', 'Soodushind'),
		new SimpleWysiwygField('Tahelepanu', 'T&auml;helepaneku tekst'),
		new ImageField('Photo', 'Mootorratta pilt'),
        	new ImageDataObjectManager( 
		$this, 
		'MootorrattasGalleryImages', // Source name
         	'MootorrattasGalleryImage', // Source class
         	'MootorrattasMyGalleryImage', // File name on DataObject
		array('MootorrattasGalleryImageTitle' => 'MootorrattasGalleryImageTitle')
		) 
		);
	}
	function Link(){ 
		return $this->Mootorrattalist()->Link() .'show/'.$this->ID;    
	}
	public function SuurHind() { 
		return $this->Hind > 50000; 
	}
}
?>

this is the dataobject

Pagetype is Mootorrattalist.php:

<?php
class Mootorrattalist extends Page
{
	static $has_many = array (
		'Mootorrattad' => 'Mootorrattas'
	);
	public function getCMSFields()
	{
		$f = parent::getCMSFields();
		$f->removeFieldFromTab("Root.Content.Main","Content");
		$manager = new DataObjectManager(
			$this, // Controller
			'Mootorrattad', 
			'Mootorrattas',
			array(
			'Mootorrattanimi' => 'Mootorrattanimi'
			),'getCMSFields_forPopup'
      ); 
      $f->addFieldToTab('Root.Content.Main', $manager); 
      return $f; 
	}
}
class Mootorrattalist_Controller extends Page_Controller
{
function show(){ 
      return array(); 
   } 
    
   function Mootorrattas(){ 
      if(isset($this->request) && $this->request->param('ID')){ 
         return DataObject::get_by_id('Mootorrattas', (int)$this->request->param('ID')); 
      }    
   }
	public function Categories() { 
	$ret = new DataObjectSet(); 
	foreach(singleton('Mootorrattas')->dbObject('MootorrattaCategory')->enumValues() as $cat) { 
	$ret->push(new ArrayData(array( 'CategoryName' => $cat, 'bikes' => DataObject::get("Mootorrattas","MootorrattaCategory = '$cat'") 
	))); 
	} 
	}
}
?>

and the .ss file:

<% control Categories %> 
$CategoryName
<% control bikes %> 
$MootorrattasField1 $MootorrattasField2 
<% end_control %> 
<% end_control %>

Avatar
Webdoc

Community Member, 349 Posts

20 November 2010 at 2:13am

can some one help an tell whats wrong why i dont see anything on my page

Avatar
UncleCheese

Forum Moderator, 4102 Posts

20 November 2010 at 3:57am

What is this?

$MootorrattasField1 $MootorrattasField2 

I don't see either of those fields on your "Mootorrattas" object..

--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com

Go to Top