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.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

Proper format to save in database and display it back on pages

Go to End

3 Posts   2013 Views


Community Member, 8 Posts

30 September 2013 at 9:36pm

Edited: 30/09/2013 9:39pm

I am trying to custom save the content of a page added in the main editor of a page. So for that i have added a quick edit option for the user in the admin/pages .. When I right click on any of the page of the site tree, with the ID of the page appended at the last in the href i fire a query in the database and display the content inside a fancy box pop up with additionally added tinymce in that pop up.
I have attached an image to see the pop up and the contents.. So when i open the pop up after right clicking on the page, how can i show the contents in the text editor in proper format. Also i run a custom query to save the data in the data base. For saving i get the content using the
var tosaveval = tinymce.get('quickedit').getContent();

So through which functions or steps i need the data in "tosaveval" to pass through to make it in a proper format to save in the data base as silver stripe does.. Also if i get the content in the variable say $content so which way should i use to display them proper in the front end or the editor..
Right now i only use addslashes(content of the editor) to save but that does not save in a proper format.
And to display i am usign stripslashes(content from db) that also does not display in a proper format..

I need the steps for saving and displaying.. like

first pas the content to addslashes then pass it to htmlspecialchars() and then run an update query in the database with the content u get after these steps..

Thanks in Advance... Please help me...

Attached Files

Community Member, 254 Posts

1 October 2013 at 6:54pm

Hi Sultan,
Nice idea.

Its hard to give advise without seeing the code, easy to copy paste your code here for others to see.

To display you can return RAW to get the plain text. This may help $mypage->Content->RAW(); That will return text without any format.

To save I would try to use Silverstripe as much as possible rather than writing your own save/serialisation functions etc.

public function quickSave() {
$pageID = $_POST['id']// get the page id you're editing
$page = DataObject::get_by_id('SiteTree', $pageID); // get the page object
$page->Content = $_POST['content']; // get the raw (no slashes) text
$page->write(); // save the content and let Silverstripe take care of serialising 



Community Member, 8 Posts

1 October 2013 at 7:29pm

Hey Bambii7 ....

Thanks for your reply.. As i have mentioned that i am using a custom page to show the content inside a fancy box pop up.. I liked your idea of using Silverstripe function to save data or display it.
I tried that and i am getting the following error..

<b>Fatal error</b>: Class 'DataObject' not found in <b>/public_html/customdirectory/GetQuickEdit.php</b> on line <b>24</b><br />

I mean i have this page but this has to do nothing with SS. Only, I have started the session and checked for logged in member.

How will I make the DataObject Class to work on any custom page in a total separate folder which doesn't even have _config.php ??

If u want to replicate this, create a different folder and place it on the root. Then make any php file and try using the SS Dataobject class. I think U too will get the same error.

What do u think ??