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.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

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

SplashPage still not working! Controller problem?!


Go to End


10 Posts   4215 Views

Avatar
Funfair77

Community Member, 49 Posts

5 November 2011 at 3:54am

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

Avatar
Howard

Community Member, 215 Posts

5 November 2011 at 12:47pm

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

Avatar
Funfair77

Community Member, 49 Posts

8 November 2011 at 2:29am

Edited: 14/11/2011 10:44pm

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

Avatar
Funfair77

Community Member, 49 Posts

11 November 2011 at 2:49am

Hello Howard,

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

Thanks in advance!

Marnix

Avatar
Funfair77

Community Member, 49 Posts

14 November 2011 at 10:44pm

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'); 

		}
	
	}

Avatar
Funfair77

Community Member, 49 Posts

16 November 2011 at 10:21am

Edited: 16/11/2011 10:39am

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

Avatar
Howard

Community Member, 215 Posts

17 November 2011 at 11:47am

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

Avatar
Funfair77

Community Member, 49 Posts

18 November 2011 at 12:36am

Edited: 18/11/2011 1:28am

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

Go to Top