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

Create custom RedirectorPage


Go to End


3 Posts   2447 Views

Avatar
bummzack

Community Member, 904 Posts

20 March 2009 at 5:44am

Hi all

I'm trying to create a custom RedirectorPage by subclassing said class like so:

class MyRedirectorPage extends RedirectorPage
{
 ...
}

Sadly, this doesn't seem to work. I can't get the new page to show up in the "Create" dropdown...
This is on SilverStripe 2.3.1 rc2.
Any clues?

Cheers - Roman

Avatar
sarge

Community Member, 4 Posts

13 August 2009 at 11:10am

Edited: 13/08/2009 11:11am

Hey,

Did you ever get anywhere with this? I'm trying to do the same thing and it won't build (keeps coming up with "Unknown class passed as parameter" as an error (see below):

[Warning] Unknown class passed as parameter
GET /[website]/index.php/dev/build?flush=1
Line 420 in E:\Inetpub\[url=http://wwwroot\[website]\sapphire\core\Object.php]wwwroot\[website/]\sapphire\core\Object.php

Source
411 	 * Prepare static variables before processing a {@link get_static} or {@link set_static}
412 	 * call.
413 	 */
414 	private static function prepare_statics($class) {
415 		// _cache_statics_prepared setting must come first to prevent infinite loops when we call
416 		// get_static below
417 		self::$_cache_statics_prepared[$class] = true;
418 
419 		// load statics now for DataObject classes
420 		if(is_subclass_of($class, 'DataObject')) {
421 			$extensions = Object::get_static($class, 'extensions');
422 			if($extensions) foreach($extensions as $extension) {
423 				if(preg_match('/^([^(]*)/', $extension, $matches)) {
424 					$extensionClass = $matches[1];
425 					DataObjectDecorator::load_extra_statics($class, $extensionClass);
426 				}
Trace
is_subclass_of(CustomRedirectorPage,DataObject) 
Line 420 of Object.php 
Object::prepare_statics(CustomRedirectorPage) 
Line 175 of Object.php 
Object::get_static(CustomRedirectorPage,db) 
Line 264 of Object.php 
Object::uninherited_static(CustomRedirectorPage,db) 
Line 2016 of DataObject.php 
DataObject::has_own_table(CustomRedirectorPage) 
Line 89 of ClassInfo.php 
ClassInfo::dataClassesFor(SiteTree) 
Line 2254 of DataObject.php 
DataObject->buildSQL(URLSegment = 'home') 
Line 2519 of DataObject.php 
DataObject->instance_get_one(URLSegment = 'home',) 
Line 2464 of DataObject.php 
DataObject::get_one(SiteTree,URLSegment = 'home') 
Line 927 of SiteTree.php 
SiteTree->requireDefaultRecords() 
Line 214 of DatabaseAdmin.php 
DatabaseAdmin->doBuild(,1) 
Line 100 of DatabaseAdmin.php 
DatabaseAdmin->build() 
Line 135 of DevelopmentAdmin.php 
DevelopmentAdmin->build(HTTPRequest) 
Line 129 of RequestHandler.php 
RequestHandler->handleRequest(HTTPRequest) 
Line 122 of Controller.php 
Controller->handleRequest(HTTPRequest) 
Line 277 of Director.php 
Director::handleRequest(HTTPRequest,Session) 
Line 121 of Director.php 
Director::direct(dev/build) 
Line 118 of main.php 
require_once(E:\Inetpub\[url=http://wwwroot\[website]\sapphire\main.php]wwwroot\[website/]\sapphire\main.php) 
Line 71 of index.php

Avatar
sarge

Community Member, 4 Posts

13 August 2009 at 11:15am

Sorry all - pls disregard cos I figured it out. Error was coming from a typo in the .php filename.

Just for completeness, all I did was as follows:

CustomRedirectorPage.php

<?php
/**
 * Defines the CustomRedirectorPage page type
 */

class CustomRedirectorPage extends RedirectorPage {
	
	static $db = array(
		);
	
	static $has_one = array(
		/* add main content images */
		"BackImage" => "Image"
		);

	/* get the CMS fields for the custom data items */
	function getCMSFields() {
		$fields = parent::getCMSFields();
		
		$fields->addFieldToTab('Root.Content.Images', new ImageField('BackImage', 'Back Image'));
		
		return $fields;
	}
}

class CustomRedirectorPage_Controller extends RedirectorPage_Controller {
	
	/* initialise the content page */
	public function init() {
		parent::init();
	}
}
?>

Thassit. :)

Cheers,

Christian