Jump to:

22979 Posts in 11815 Topics by 2826 members

General Questions

SilverStripe Forums » General Questions » Proper format to save in database and display it back on pages

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

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

Page: 1
Go to End
Author Topic: 397 Views
  • Sultan
    Avatar
    Community Member
    8 Posts

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

    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
  • Bambii7
    Avatar
    Community Member
    254 Posts

    Re: Proper format to save in database and display it back on pages Link to this post

    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

    }

  • Sultan
    Avatar
    Community Member
    8 Posts

    Re: Proper format to save in database and display it back on pages Link to this post

    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 ??

    397 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.