7913 Posts in 1355 Topics by 930 members
DataObjectManager Module
SilverStripe Forums » DataObjectManager Module » Preview: DataObjectManager module
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: | 54314 Views |
-
Re: Preview: DataObjectManager module

4 April 2009 at 7:30am Last edited: 4 April 2009 7:30am
Cause of the issue mentioned in my post of 1 April 2009 at 10:03am:
Using the line from trunk, the pop-up's save button works correctly; with the line from nestedurls, it does not.
Ben
.
My post of 1 April 2009 at 10:03am:
I'm running revision 103 of DataObjectManager against revision 73881 of trunk. When I click the "save" button on the "add" pop-up window, the object I'm trying to add never gets saved to the database. Instead, I get sent to some kind of page that has an add link and a search box, etc.The "add" pop-up window's form tag is as follows:
<form id="DataObjectManager_Popup_AddForm" action="admin/EditForm/field/Articles?ctf[Articles][per_page]=10&ctf[Articles][showall]=0&ctf[Articles][sort]=Created&ctf[Articles][sort_dir]=DESC&ctf[Articles][search]=&ctf[Articles][filter]=" method="post" enctype="application/x-www-form-urlencoded">Is that the correct action? It looks funny to me.
-
Re: Preview: DataObjectManager module

4 April 2009 at 9:10am
Hi Uncle Cheese
Fantastic work! The DataObjectManager is just what I needed.
Do you have an example of how to setup ManyManyDataObjectManager? I want to use it to enable users to select images to go in the right column on the page and have have the ability to have different images on everypage. I might have missed something but when I use DataObjectManager it puts the same objects on every page.
Thanks
Aaron
-
Re: Preview: DataObjectManager module

4 April 2009 at 9:19am Last edited: 4 April 2009 9:19am
Hi, Aaron.
Great use of the DataObjectManager. I'd recommend using a ManyManyFileDataObjectManager if I were you, since it will display the images in a grid for you, as well as streamline the upload process.
If you have the many_many relation set up correctly, it should be the same as a ManyManyComplexTableField, only with one more argument.
new ManyManyFileDataObjectManager(
$this,
'MyImages'
'MyImage',
'Image' // The fieldname on the $has_one array of your MyImage dataobject.
array( // headers...
'getCMSFields_forPopup'
);You can read more in the documentation in the SS wiki.
-
Re: Preview: DataObjectManager module

4 April 2009 at 10:06am
Uncle Cheese. Thank you for all your hard work and help.
I would like to use the Testimonials page type to manage testimonials. I have set up the page so that I can add testimonials and I can see the database table where they are stored. What I don't know how to do is randomly grab a Testimonial and display it on any give page on the site. My guess is that in the Page_Controller I would have a function that could select a random Testimonial from the database and display the Testimonial Content and Author on my page. I don't need a page that shows all of the Testimonials.
-
Re: Preview: DataObjectManager module

4 April 2009 at 10:13am
Page_Controller
function RandomTestimonial()
{
return DataObject::get_one("Testimonial", null, true, "RAND()");
}FYI: Please do not rely on the example code included with dataobject_manager. I'll be removing it soon. You can recreate it in mysite/code if you want.
-
Re: Preview: DataObjectManager module

8 April 2009 at 1:55pm
I have a simple question regarding the display of content in a template. I'm using FileDataObjectManager and my files are as follows:
Partner.php
-----------
<?php
class Partner extends DataObject
{
static $db = array (
'Name' => 'Text',
'URL' => 'Text'
);
static $has_one = array (
'Logo' => 'File',
'PartnerPage' => 'PartnerPage'
);
public function getCMSFields_forPopup()
{
return new FieldSet(
new TextField('Name'),
new TextField('URL'),
new FileIFrameField('Logo')
);
}
}
?>
-----------PartnerPage.php
-----------
<?php
class PartnerPage extends Page
{
static $has_many = array (
'Partners' => 'Partner'
);
public function getCMSFields()
{
$f = parent::getCMSFields();
$manager = new FileDataObjectManager(
$this, // Controller
'Partners', // Source name
'Partner', // Source class
'Logo', // File name on DataObject
array(
'Name' => 'Name',
'URL' => 'URL'
), // Headings
'getCMSFields_forPopup' // Detail fields (function name or FieldSet object)
// Filter clause
// Sort clause
// Join clause
);
// If undefined, all types are allowed. Pass with or without a leading "."
$manager->setAllowedFileTypes(array('jpg','gif'));
// Label for the upload button in the popup
$manager->setBrowseButtonText("Upload (JPG or GIF only)");
// In grid view, what field will appear underneath the icon. If left out, it defaults to the file title.
$manager->setGridLabelField('Name');
// Plural form of the objects being managed. Used on the "Add" button.
// If left out, this defaults to [MyObjectName]s
$manager->setPluralTitle('Partners');
$f->addFieldToTab("Root.Content.Partners", $manager);
$f->removeFieldFromTab('Root.Content', 'HeaderImage');return $f;
}}
class PartnerPage_Controller extends Page_Controller
{
}
?>
-----------PartnerLogo.ss
-----------
<% if Partners %>
<div id="partners"><div class="container">
<div id="partner-logos">
<ul>
<% control Partners %>
<li class="partner-logo"><a href="#" title="$Name" style="background-image: url('$Logo.URL')"><span>$Name</span></a></li>
<% end_control %>
</ul>
</div>
</div></div><!-- end #partners -->
<% end_if %>
-----------Can anyone tell me why the above template file PartnerLogos.ss does not return any Partners, when in the CMS I clearly have added records using dataobjectmanager and I can see them under the Partners tab in the CMS?
-
Re: Preview: DataObjectManager module

8 April 2009 at 2:04pm
First of all, this is really eerie. I literally created exactly the same code using the FileDataObjectManager about a week ago. Exactly the same class names and relationship names. What a weird coincidence that is. So similar, I was actually starting to worry that someone had hacked into my server and stolen the code.
Anyway..
The most flagrant error I see in your code is that your template is called PartnerLogo.ss, but your Page class is PartnerPage. What's up with that?
-
Re: Preview: DataObjectManager module

8 April 2009 at 2:10pm Last edited: 8 April 2009 2:11pm
Thank you UncleCheese! The issue has been sorted. PartnerLogo.ss is just an Include file. The reason <% if Partners %> was not returning anything was because I hadn't added a check to see if I was actually on the Partner page. All sorted now.
BTW, this is by far the most useful SS module! Many Thanks!
| 54314 Views | ||
| Go to Top | Next > |

