Jump to:

10928 Posts in 2612 Topics by 1809 members

All other Modules

SilverStripe Forums » All other Modules » How to show last guestbook entry in the sidebar

Discuss all other Modules here.

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

Page: 1
Go to End
Author Topic: 1395 Views
  • Mauro74
    Avatar
    Community Member
    30 Posts

    How to show last guestbook entry in the sidebar Link to this post

    Hi all.

    Does anyone knows how or point me in the direction to show the last guestbook entry(using the simple guestbook module) in the sidebar?

    Thanks in advance.

  • Euphemismus
    Avatar
    Community Member
    82 Posts

    Re: How to show last guestbook entry in the sidebar Link to this post

    Good morning,

    do you have programming skills? Otherwise I'd have to implement that ;-)

    If you do it yourself:
    Create a new dataobject and select from table 'GuestbookEntry', either by date ('Created') or by MAX ID (latest should be the current guestbook entry).

    Kind regards,
    Marc

  • Mauro74
    Avatar
    Community Member
    30 Posts

    Re: How to show last guestbook entry in the sidebar Link to this post

    Hi Marc,
    I do have 'some' php programming skills, but mostly front-end.

    Do you mean having something like:

    function guestPosts(){
          $posts = DataObject::get('GuestbookEntry', '', 'Created', '');
          return $posts;
       }

    I assume that the function has to be in Page.php to be available for all the pages and then having something in the Sidebar.ss like:

    <% control guestPosts %>
          <p>$Comment</p>
    <p>By $FirstName - $Created.Nice</p>
    <br>
    <% end_control %>

    The thing I'm not sure of, is the query itself -

    DataObject::get(...);

    - could you help me with that please?

    Thanks a lot!

  • Euphemismus
    Avatar
    Community Member
    82 Posts

    Re: How to show last guestbook entry in the sidebar Link to this post

    Hi Mauro74,

    yes, that was the solution I'd suggest ;-)
    Problematic is the relation of entries to comments if you want to show those, too.
    A good resource for this issue is this
    What you need is (sql):

    SELECT *
    FROM `GuestbookEntry`
    ORDER BY Created DESC
    LIMIT 5


    put into a dataobject:

    $objData = DataObject::get(
       'GuestbookEntry',
       '', //filter
       'Created', //sort by
       '', //join
       '5' //limit
    );


    That's also correct in your example - I'm not sure about the sort... I'm faintly remembering, one has to add "ORDER BY" or sth, even in the method call, but I can't test right now (and I mostly use raw SQL and covert results to dataObjectSets). Nevertheless you're also able to add the comments in the join clause.

    Packed into your suggested method and calling it via frontend should do the trick. If you create an own extension to the page class in your /mysite directory (see the tutorials), you should be able to add this data to the sidebar on all pages.

    Kind regards,
    Marc

  • Mauro74
    Avatar
    Community Member
    30 Posts

    Re: How to show last guestbook entry in the sidebar Link to this post

    Hi Marc,

    I don't need to show the comments, no problem about it. I implemented the query as you suggested and simply by putting the function into Page.php and calling it in an include file called in the sidebar it works like a breeze!

    One more thing. I have an issue with reCaptcha. When I try to enter a new guestbook entry from the website (not in the cms) I have this error:

    Fatal error: Call to undefined function curl_init() in C:\xampp\htdocs\website\recaptcha\code\RecaptchaField.php on line 363

    Is it because I'm running the website on my localhost? By the way I've got the reCaptcha keys and all that set in the _config file.

    Thanks for you help!

  • Euphemismus
    Avatar
    Community Member
    82 Posts

    Re: How to show last guestbook entry in the sidebar Link to this post

    Hi,

    the CURL error could have a few causes, most likely your local webserver or php-configuration. CURL is used to access remote server content (I think, the captcha images) and if that is blocked or CURL not installed/initialized in your local environment: error.

    Kind regards,
    Marc

    1395 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.