7921 Posts in 1359 Topics by 933 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Need help to show dataobject on page
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: | 1988 Views |
-
Re: Need help to show dataobject on page

14 September 2010 at 4:27am
In cms i make page using pagetype nimekri then i can add objekt's under it but in frontend i see only the listing i also need the full detail page mysite.com/nimekiri/someobjekt/
that is the problem.
is there any way to do that or what i need to change in my code to allow that.
-
Re: Need help to show dataobject on page

14 September 2010 at 5:15am
Well thats exactly what's this page is all about:
http://www.ssbits.com/using-silverstripe-url-parameters-to-display-dataobjects-on-a-page
Especially from Part 3..
Example for Nimekri.php . I did not test is, but something like this should work.
<?php
class Nimekri extends Page{
// .....
static $has_many = array (
'Objektid' => 'Objekt'
);
// .....
}class Nimekri_Controller extends Page_Controller{
static $allowed_actions = array(
'show'
);
function init(){
parent::init();
}
/**
* In template
* <% if show %>
* <% control show %>
* $Objektinimi
* $Kirjeldus
* <% end_control %>
* <% end_if %>
*
*/
function show($request){
if($request->param('ID')){
$obj = DataObject::get_by_id('Objekt', (int)$request->param('ID'));
return $this->customise($obj)->renderWith(array('Nimekri'));
}
}
}class Objekt extends DataObject{
// .....
// Use this to link to a single Objekt
function Link(){
return $this->Nimekiri()->Link() .'show/'.$this->ID;
}
// .....
} -
Re: Need help to show dataobject on page

14 September 2010 at 5:31am
Strange but i dont get it work
used code:
nimekiri.php<?php
class Nimekiri extends Page
{
static $has_many = array (
'Objektid' => 'Objekt'
);
static $allowed_actions = array(
'show'
);public function getCMSFields()
{
$f = parent::getCMSFields();
$f->removeFieldFromTab("Root.Content.Main","Content");
$manager = new DataObjectManager(
$this,
'Objektid',
'Objekt',
array('Objektinimi' => 'Objekti nimi', 'Kirjeldus' => 'Objekti kirjeldus'),
'getCMSFields_forPopup'
);
$f->addFieldToTab('Root.Content.Main', $manager);
return $f;
}}
class Nimekiri_Controller extends Page_Controller {
function init(){
parent::init();
}
function show($request){
if($request->param('ID')){
$obj = DataObject::get_by_id('Objekt', (int)$request->param('ID'));
return $this->customise($obj)->renderWith(array('Nimekri'));
}
}
}
?>
objekt.php:<?php
class Objekt extends DataObject
{
static $db = array (
'Objektinimi' => 'Text',
'Kirjeldus' => 'HTMLText',
'Hind' => 'Text',
'Elamutyyp' => "Enum('Korter, Maja, Aripind, Suvila, Ridaelamu, Paarismaja, Maatykk')",
'Soojaveetyyp' => "Enum('Keskkyte, Elekter')",
'Kyttetyyp' => "Enum('Keskkyte, Elekter, Puukyte')",
'Tubadearv' => "Enum('1, 2, 3, 4,5,rohkem')",
'Krundisuurus' => 'Text',
'Yldpind' => 'Text',
'Korrus' => 'Text',
'Vannitube' => 'Text',
'Tualette' => 'Text',
'Aadress' => 'Text',
'Linn' => 'Text',
'Vald' => 'Text',
'Maakond' => 'Text'
);
static $has_one = array (
'Nimekiri' => 'Nimekiri',
'Photo' => 'Image'
);
static $has_many = array (
'GalleryImages' => 'GalleryImage'
);
static $searchable_fields = array(
'Elamutyyp' => 'ExactMatchFilter',
'Yldpind' => 'ExactMatchFilter',
'Linn' => 'ExactMatchFilter',
'Tubadearv' => 'ExactMatchFilter'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Objektinimi'),
new SimpleWysiwygField('Kirjeldus'),
new DropdownField(
'Elamutyyp',
'Elamutyyp',
singleton('Objekt')->dbObject('Elamutyyp')->enumValues()),
new DropdownField(
'Soojaveetyyp',
'Soojaveetyyp',
singleton('Objekt')->dbObject('Soojaveetyyp')->enumValues()),
new DropdownField(
'Kyttetyyp',
'Kyttetyyp',
singleton('Objekt')->dbObject('Kyttetyyp')->enumValues()),
new TextField('Hind'),
new TextField('Krundisuurus'),
new TextField('Yldpind'),
new DropdownField(
'Tubadearv',
'Tubadearv',
singleton('Objekt')->dbObject('Tubadearv')->enumValues()),
new TextField('Korrus'),
new TextField('Vannitube'),
new TextField('Tualette'),
new ImageField('Photo'),
new TextField('Aadress'),
new TextField('Linn'),
new TextField('Vald'),
new TextField('Maakond'),
new ImageDataObjectManager(
$this,
'GalleryImages', // Source name
'GalleryImage', // Source class
'MyGalleryImage', // File name on DataObject
array('Pildinimi' => 'Pildinimi'))
);
}
public function getCustomSearchContext() {
$fields = $this->scaffoldSearchFields(array('Elamutyyp','Yldpind','Linn','Tubadearv')
);
$filters = array(
'Elamutyyp' => new ExactMatchFilter('Elamutyyp'),
'Yldpind' => new ExactMatchFilter('Yldpind'),
'Linn' => new ExactMatchFilter('Linn'),
'Tubadearv' => new ExactMatchFilter('Tubadearv')
);
return new SearchContext(
$this->class,
$fields,
$filters
);
}
function Link(){
return $this->Nimekiri()->Link() .'show/'.$this->ID;
}
}
?>
and nimekiri.ss:<div class="typography">
<h2>$Title</h2>
<% if show %>
<% control show %>
<div class="pilt">
<table width="300" border="0">
<tr>
<td><h4>$Objektinimi</h4></td>
</tr>
<tr>
<td valign="top"><table width="300" height="130" border="0">
<tr>
<td width="130" align="left" valign="top"><a href="{$Top.URLSegment}/{$ID}" title="$Objektinimi">$Photo.SetWidth(120)</a></td>
<td align="left" valign="top">
<% if Hind %><span style="font-size:11px;"><% _t("MYYGIHIND","Müügihind") %>:<strong>$Hind</strong></span><br /><% end_if %>
<% if Yldpind %><span style="font-size:11px;"><% _t("YLDPIND","Üldpind") %>: <strong>$Yldpind</strong></span><br /><% end_if %>
<% if Krundisuurus %><span style="font-size:11px;"><% _t("KRUNT","Krundi suurus") %>: <strong>$Krundisuurus</strong></span><br /><% end_if %>
<p style="font-size:11px;"><br /><a href="$link" title="$Objektinimi"><% _t("INFO","Detailne info") %></a></p></td>
</tr>
</table></td>
</tr>
</table>
</div>
<% end_control %>
<% end_if %>
$Content
$PageComments
$Form
<div class="clear"><!-- --></div>
</div>
<div style="margin-bottom:20px;"></div> -
Re: Need help to show dataobject on page

14 September 2010 at 6:05am
What does that mean? "Can't get it to work"?
You need to describe the problem you're having in order for us to help you.
--------------------
SilverStripe tips, tutorials, screencasts and more: http://www.leftandmain.com -
Re: Need help to show dataobject on page

14 September 2010 at 6:06am
static $allowed_actions = array(
'show'
);needs to be in your controller
-
Re: Need help to show dataobject on page

14 September 2010 at 6:09am
but it on nimekiri.php in controler fisrt before function init(){
parent::init();
}
but then it doesnt show anything in mysite/nimekiri/ -
Re: Need help to show dataobject on page

14 September 2010 at 6:16am
If you want to display the object, you need to access it with www.yoursite.com/nimekiripageurl/show/23 (ObjektID)
I really advise you to play with the tutorial on SSBits. Easier then that you probably won't get..
http://www.ssbits.com/using-silverstripe-url-parameters-to-display-dataobjects-on-a-page
There is a download with the complete files you can use as an example:
http://www.ssbits.com/assets/Uploads/AttachedFiles/AttachedFiles/CompletedfilesURLParams.zip
-
Re: Need help to show dataobject on page

14 September 2010 at 6:18am Last edited: 14 September 2010 7:10am
nothing i gonna show up not in main page and also not in objekt place to i need to make some new template under layout like objekt.ss
| 1988 Views | ||
| Go to Top | Next > |


