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.

Archive

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Add custom content to the system


Go to End
Reply

17 Posts   4860 Views

Avatar
Mednezz

25 September 2007 at 5:18am (Last edited: 25 September 2007 5:19am), Community Member, 23 Posts

Hey Guys!

I've made a certain pagetype with my own set of data fields. The administrator can add the pages without any problem using the cms. But now i've got a private public section where logged in visitors should also be able to add those kind of pages.

When building the DB SS has made 3 tables :

[pagetype]Page
[pagetype]Page_Live
[pagetype]Page_versions

Now i've made a form containing al the fields needed and when i process that form i could create an object $obj = new [pagetype]Page; and then $form->saveInto($obj);

But! ;-)

I also need it to get into the sitetree so the page can be called with an url.

Finally my questions..

Are there functions inside SS so i can automatically publish the latest added page to the _Live table and how should i get it into the SiteTree / SiteTree_Live

Hopefully i'm clear enough!

Thanks in advance!

Avatar
dio5

25 September 2007 at 6:10am Community Member, 501 Posts

I'm going to face more or less the same problem in the next few weeks somewhere... and keen on seeing someone else's solution to this too.

In my site people will be adding stuff via the frontend that has to become a page in the sitetree.

So I'll have a class 'Tip', and logged in users will be able to submit a tip... not a problem, but every tip is a subpage of tipholderpage in the cms-sitetree too...

Avatar
Mednezz

25 September 2007 at 7:27am Community Member, 23 Posts

Yep, same thing here, my to be added pages are also a child of an holder.

Have found some functions in /sapphire/core/model/versioned and especially function publish() ;)

But would like to ask the core dudes what the best approach would be :)

Curious to what they have to say!

Avatar
Ingo

25 September 2007 at 2:47pm Forum Moderator, 801 Posts

yeah, you should use $myPageObj->publish() for that.
for getting the page into the sitetree, i'd use the URLSegment to get the holder,
and set $myPageObj->ParentID.
you might want to add additional security in onBeforeWrite() to make sure nobody will add certain fields, or change the pagetype etc.:

class MyPage extends Page {
function onBeforeWrite() {
// if record is created
if(!$this->ID) {
// if no valid login
if(!Member::currentUser()) {
// filter $this->record-array for allowed values
}
}
parent::onBeforeWrite();
)


alternatively, this can be done in the form-saving code.

Avatar
dio5

29 September 2007 at 1:18am (Last edited: 29 September 2007 2:37am), Community Member, 501 Posts

@Mednezz (or anyone else having done this)

I was wondering if you managed to do it eventually?

In the form-saving function do you actually create a new Page and new SiteTree too? I mean how did you handle the fields like URLSegment, MenuTitle...

If you could point me to an example that could get me started, that would be fantastic.

Avatar
dio5

29 September 2007 at 4:23am (Last edited: 29 September 2007 4:29am), Community Member, 501 Posts

What I have now seems to add to Tip_Live and SiteTree_Live, but doesn't seem to pass it correctly to Tip and SiteTree.
Moreover it gives a fatal error...

What I have basically in the save-function of my form is:

$tip = new Tip();
         
$tip->Street = $data['Street'];
$tip->StreetNumber = $data['StreetNumber'];
// a lot of tip properties...
   
// Then I set the properties inherited from SITETREE
// Do I have to set ClassName? Do I have to set ViewersGroup?

$tip->Title = $data['Title'];
$tip->Content = "test";
$tip->ClassName = "Tip";
$tip->Status = "Published";
$tip->Viewers = "Anyone";
$tip->ParentID = 2;
      
/* And here I have to write it to all the tables.. and this is where I'm doing something wrong, but I'm not sure what or how to do it, can't find any documentation about it...:*/

$tip->write();
$tip->writeToStage("Stage"); // Is this correct?
$tip->publish("Stage", "Live"); // this?

I checked out the blog-code and based my code a bit on that one.. but obviously something is wrong.

the fatal error was:
FATAL ERROR: Can't find testtitle/22 in stage Stage
At line 300 in D:\htdocs\silv21rc\sapphire\core\model\Versioned.php

As mentioned before: the data is in the tables Tip_Live and SiteTree_Live, but not in Tip and SiteTree...

Avatar
dio5

29 September 2007 at 10:09am Community Member, 501 Posts

If only someone could provide some answers to these, probably not even hard, questions...??

Avatar
Ingo

29 September 2007 at 1:46pm (Last edited: 29 September 2007 1:48pm), Forum Moderator, 801 Posts

usually in a method called by a form, you'll have two parameters: $data and $form.
based on the $data, you usually just get an object that needs to be altered (e.g. through $data['ID']). alternatively you create a new object, same thing.

then you just call $form->saveInto($myObject), so you don't have to do all the property-setting yourself. just another $myObject->publish() call should be needed in your case (the writing to stage should happen automatically afaik)

Go to Top