Jump to:

23367 Posts in 18143 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » SplashPage still not working! Controller problem?!

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 2
Go to End
Author Topic: 1489 Views
  • Funfair77
    Avatar
    Community Member
    49 Posts

    SplashPage still not working! Controller problem?! Link to this post

    Hello,

    I have a question.

    There are QR codes on my website, they bring you to there mobile page version. Now I want that before the page you request opens an another page shows up. A kind of generic welcome page. On that page here is a go next button and open the actual page.

    In short: I want to declare in my backend to each page if a generic welcome page should appear first yes or no. The welcome page Next button know what the next page is.

    My clue was http://www.website.com/Security/login?BackURL=%2Fadmin didn't work out.

    Anyway, I have no idea how to get this working.

    If it is unclear let me know.

    Thank you!

    Marnix

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: SplashPage still not working! Controller problem?! Link to this post

    Hey yea this is reasonably easy to do.

    I imagine you want to create a SplashPage.php then in its controller add this code:

    function NextPage()
    {
          if (isset($_GET['nextPage'])) {
             return DataObject::get_by_id('Page', $_GET['nextPage']);
          }
    }


    Then in the template for SplashPage create the link to the next page by putting in:

    <a href="$NextPage.Link"> $NextPage.Title </a>

    You can then direct users to www.yoursite.com/splashpage?nextPage=15 where '15' is the ID of whatever page you want to link to. If you want you could mess round with this and actually include the title of the page instead of the ID but this will get you started.

    Howard

  • Funfair77
    Avatar
    Community Member
    49 Posts

    Re: SplashPage still not working! Controller problem?! Link to this post

    Hello Howard.

    Thnx for your reply.
    This is exactly what I want, but it's still not working.

    First I tried this
    I created the page mysite/code/SplashPage.php

    <?php
    class SplashPage extends SiteTree {

       public static $db = array(
       );

       public static $has_one = array(
       );

    }

    class SplashPage_Controller extends ContentController {

       /**
        * An array of actions that can be accessed via a request. Each array element should be an action name, and the
        * permissions or conditions required to allow the user to access it.
        *
        * <code>
        * array (
        * 'action', // anyone can access this action
        * 'action' => true, // same as above
        * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
        * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
        * );
        * </code>
        *
        * @var array
        */
       public static $allowed_actions = array (
       );

       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          Requirements::themedCSS('layout');
          Requirements::themedCSS('typography');
          Requirements::themedCSS('form');

          }
       }

       function NextPage()
       {
           if (isset($_GET['nextPage'])) {
              return DataObject::get_by_id('Page', $_GET['nextPage']);
           }
       }

    And the templates
    /themes/blackcandy/templates/SplashPage.ss

    and

    themes/blackcandy/templates/Layout/SplashPage.ss

    In the last template there is this code:

    <a href="$NextPage.Link"> $NextPage.Title </a>

    Flush the page, but...

    This didn't worked out, so I deleted this

       function NextPage()
       {
           if (isset($_GET['nextPage'])) {
              return DataObject::get_by_id('Page', $_GET['nextPage']);
           }
       }

    from mysite/code/SplashPage.php and created this foder /mysite/code/Controllers/ with the page SplashPage.php

    <?php

       function NextPage()
       {
           if (isset($_GET['nextPage'])) {
              return DataObject::get_by_id('Page', $_GET['nextPage']);
           }
       }

    ?>

    But now I have no idea how to activate this Controllers php file from the _config file.

    Please help, thank You!

    Marnix

  • Funfair77
    Avatar
    Community Member
    49 Posts

    Re: SplashPage still not working! Controller problem?! Link to this post

    Hello Howard,

    Did you have the time to look at my answer, I do not get it fixed (grrrr...).

    Thanks in advance!

    Marnix

  • Funfair77
    Avatar
    Community Member
    49 Posts

    Re: SplashPage still not working! Controller problem?! Link to this post

    Ok, I think the problem is the position of the script in the controller. This is my script of the page http://www.website.com/mysite/code/SplashPage.php

    Please, help.

    Marnix

    <?php
    class SplashPage extends SiteTree {

       public static $db = array(
       );

       public static $has_one = array(
       );

    }

    class SplashPage_Controller extends ContentController {

       function NextPage()
       {
    if (isset($_GET['nextPage'])) {
    return DataObject::get_by_id('Page', $_GET['nextPage']);
    }
       }
       
       /**
        * An array of actions that can be accessed via a request. Each array element should be an action name, and the
        * permissions or conditions required to allow the user to access it.
        *
        * <code>
        * array (
        * 'action', // anyone can access this action
        * 'action' => true, // same as above
        * 'action' => 'ADMIN', // you must have ADMIN permissions to access this action
        * 'action' => '->checkAction' // you can only access this action if $this->checkAction() returns true
        * );
        * </code>
        *
        * @var array
        */
       public static $allowed_actions = array ();

       public function init() {
          parent::init();

          // Note: you should use SS template require tags inside your templates
          // instead of putting Requirements calls here. However these are
          // included so that our older themes still work
          Requirements::themedCSS('layout');
          Requirements::themedCSS('typography');
          Requirements::themedCSS('form');

          }
       
       }

  • Funfair77
    Avatar
    Community Member
    49 Posts

    Re: SplashPage still not working! Controller problem?! Link to this post

    Hello everybody!

    My SplashPage is still not working.

    Is the http://www.website.com/mysite/code/SplashPage.php script ok? See my last post.

    Do I need to add something to the _config.php file?
    // SplashPage
    Object:: ...

    Someone a clue? Thank you. It Driving me nuts

    Marnix

  • Howard
    Avatar
    Community Member
    215 Posts

    Re: SplashPage still not working! Controller problem?! Link to this post

    Hey Marnix - sorry I forgot to subscribe to this topic so didn't get the email when you replied.

    I copy and pasted the code you posted and got it to work with a small change.
    - the "class SplashPage extends SiteTree" should be "class SplashPage extends Page"
    - the "class SplashPage_Controller extends ContentController" should be "class SplashPage_Controller extends Page_Controller"

    Then you need to create a template file that will be /themes/yourTheme/templates/Layout/SplashPage.ss - For that file you can just have all the normal stuff but include:

    <a href="$NextPage.Link"> $NextPage.Title </a>

    Then once you've built the database with www.yoursite.com/dev/build you will be able to create a splash page in the CMS. To activate the "Next Page" link you just need to create the append the ID of the page that you want to link to to the URL of the splash page, so it will look something like this: www.yoursite.com/splash-page-title?nextPage=2

    I'll subscribe this time so let me know how it goes, if you get stuck on any errors tell us what they are rather than just saying "it doesn't work" as it makes it easier to troubleshoot.

    Howard

  • Funfair77
    Avatar
    Community Member
    49 Posts

    Re: SplashPage still not working! Controller problem?! Link to this post

    Hello Howard,

    I change my answer, because it works, I used id numbers that didn't exict! Brilliant!
    Thank you very much. Also I tested it with the url, but in your code I see it's looks for an id, not a text.

    Now I have to figure out an easy way to lookup the id numbers of the pages. Hint ?!

    Have a nice day.

    Marnix

    1489 Views
Page: 1 2
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.