7911 Posts in 1354 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » How to call action from dataobject
Discuss the DataObjectManager module, and the related ImageGallery module.
Moderators: martimiz, UncleCheese, Howard, Sean, Ryan M., biapar, Willr, Ingo, swaiba, simon_w
| Go to End | Next > | |
| Author | Topic: | 1341 Views |
-
How to call action from dataobject

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
-
Re: How to call action from dataobject

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?
-
Re: How to call action from dataobject

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.ssif 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.
-
Re: How to call action from dataobject

17 November 2010 at 5:10am Last edited: 17 November 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
-
Re: How to call action from dataobject

17 November 2010 at 5:34am Last edited: 17 November 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 %> -
Re: How to call action from dataobject

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õimsus'),
new TextField('Poordemoment', 'Pöördemoment'),
new TextField('Surveaste', 'Surveaste'),
new TextField('Kytusesisselase', 'Kütuse sisselase'),
new TextField('Tippkiirus', 'Tippkiirus'),
new TextField('Kaivitussysteem', 'Käivitussüsteem'),
new TextField('Sidur', 'Sidur'),
new TextField('Kaigukast', 'Käigukast'),
new TextField('Amordid', 'Amordid'),
new TextField('Pidurid', 'Pidurid'),
new TextField('Rattad', 'Rattad'),
new TextField('Istmekorgus', 'Istmekõrgus'),
new TextField('Bensiinipaak', 'Bensiinipaak'),
new TextField('Tyhimass', 'Tühimass'),
new TextField('Varvid', 'Värvid'),
new TextField('Garantii', 'Garantii'),
new TextField('Muuinfo', 'Muu info'),
new TextField('Hind', 'Hind'),
new TextField('Soodushind', 'Soodushind'),
new SimpleWysiwygField('Tahelepanu', 'Tä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 dataobjectPagetype 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 %> -
Re: How to call action from dataobject

20 November 2010 at 2:13am
can some one help an tell whats wrong why i dont see anything on my page
-
Re: How to call action from dataobject

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
| 1341 Views | ||
| Go to Top | Next > |

