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.

Template Questions /

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

Changing background on each page without tons of templates


Go to End
Reply


26 Posts   8131 Views

Avatar
evsoul

Community Member, 36 Posts

26 January 2010 at 11:04am

Yeah I figured that would be a very vague error haha.

I'll check server logs, but also how do I put the site in dev mode?

Avatar
evsoul

Community Member, 36 Posts

26 January 2010 at 11:37am

Edited: 26/01/2010 11:38am

Ok, I put it into dev mode and this is the error I got in replacement.


[Notice] Undefined index:
POST /sites/carreramarble/BETA/images/index/Page/1/Background/EditImageForm

Line 157 in /nfs/www/WWW_pages/gsarpy/gregsarpy.net/sites/carreramarble/BETA/sapphire/core/ClassInfo.php

Source

148 	/**
149 	 * @todo Improve documentation
150 	 */
151 	static function ancestry($class, $onlyWithTables = false) {
152 		global $_ALL_CLASSES;
153 
154 		if(is_object($class)) $class = $class->class;
155 		else if(!is_string($class)) user_error("Bad class value " . var_export($class, true) . " passed to ClassInfo::ancestry()", E_USER_WARNING);
156 
157 		$items = $_ALL_CLASSES['parents'][$class];
158 		$items[$class] = $class;
159 		if($onlyWithTables) foreach($items as $item) {
160 			if(!DataObject::has_own_table($item)) unset($items[$item]);
161 		}
162 		return $items;
163 	}
Trace

ClassInfo::ancestry() 
Line 1364 of DataObject.php
DataObject->db(Name) 
Line 1799 of DataObject.php
DataObject->getField(Name) 
Line 109 of ViewableData.php
ViewableData->__get(Name) 
Line 253 of File.php
File->onBeforeWrite() 
Line 783 of DataObject.php
DataObject->write() 
Line 737 of Image.php
Image_Uploader->save(Array,Form,HTTPRequest) 
Line 241 of Form.php
Form->httpSubmission(HTTPRequest) 
Line 129 of RequestHandler.php
RequestHandler->handleRequest(HTTPRequest) 
Line 143 of RequestHandler.php
RequestHandler->handleRequest(HTTPRequest) 
Line 119 of Controller.php
Controller->handleRequest(HTTPRequest) 
Line 277 of Director.php
Director::handleRequest(HTTPRequest,Session) 
Line 121 of Director.php
Director::direct(/images/index/Page/1/Background/EditImageForm)
Line 118 of main.php

What do you think? Or do I need more?

Avatar
evsoul

Community Member, 36 Posts

26 January 2010 at 2:01pm

Edited: 26/01/2010 2:39pm

Is there a way to assign a background image to each page by say ID number? i dunno.
something that's less involving. i won't have the need for adding pages/backgrounds once the site is done.

Avatar
DowntownScience

Community Member, 13 Posts

10 July 2014 at 11:16am

Edited: 10/07/2014 11:17am

Let me preface by saying that I'm not a programmer!

I added the suggested code to both page.ss (templates root, not the one in layout) and page.php. I rebuilt/flushed and have the ability to add a background from CMS. I add the background without error and save the page, but when I refresh the page I do not see the background image.

I have created multiple page types in template that call a specific banner image, ie...

<% include SideBar %>
<div class="content-container unit size3of4 lastUnit">
<article>
<div id="Banner">
<h1><img src="themes/simple/images/Molecule2Banner.jpg" alt="Homepage image" /></h1>
</div>
<div class="content">$Content</div>
</article>
$Form
$PageComments
</div>

Could this be interfering? I tried changing the page type to "page" which has been left at default settings but the banner image just goes away and I still don't see a background.

Any help you can give is much appreciated.

Avatar
mhdesign

Community Member, 206 Posts

30 May 2016 at 4:59pm

Really useful thread and I've learned a lot! Being able to customise SilverStripe in this way is a great feature. But, typically, SilverStripe is falling at the final hurdle.

I'm creating a Landing Page template where the background images can be changed out (better than having lots of Landing Page templates for individual background images, right?). As I'm a Designer (not a Programmer), I've been cutting and pasting from this thread, then flushing and /dev/build/ing until the DB stopped falling over, at which point LandingPage.php looked like this:

<?php
/**
 * Defines the LandingPage page type
 */
 
class LandingPage extends EnquiryPage {
   static $db = array(
  );   
  static $has_one = array( 
     'Background' => 'Image' 
  );

function getCMSFields() {
		$fields = parent::getCMSFields();
		// add the upload control for the background image to the cms 
     $fields->addFieldToTab('Root.Content.Main', new ImageField('Background')); 
		return $fields;
	}
}

class LandingPage_Controller extends EnquiryPage_Controller {     
}

Only problem is when I go to touch a page that uses this template in the CMS I get a pause, then a simple little black box that says:
Internal Server Error X
So near and yet so far...

Any clues?

Avatar
Friizu

Community Member, 17 Posts

30 May 2016 at 8:56pm

Edited: 30/05/2016 9:01pm

ImageField is deprecated use UploadField instead examp:

$fields->addFieldToTab("Root.Main", new UploadField('Background'));

Also not sure what's your EnquiryPage? What happens if u extend just page?

class LandingPage extends Page {
/* ... */
class LandingPage_Controller extends Page_Controller {

Let me know if it solved your problem ;)

ps. u get better error reporting when u set your site in dev mode.

Avatar
mhdesign

Community Member, 206 Posts

31 May 2016 at 12:22pm

Edited: 31/05/2016 12:41pm

Hey Friizu, thanks for your reply! Well, now I have a different problem, at least that's progress...

It's now telling me:

Notice at line 174 of /Users/mike/Sites/New/framework/dev/deprecation.php

I'm not sure what this means?
There's a contact form on the page (essential for a landing page) so that's what EnquiryPage is all about. I will try it on Page as well just to see...

And yes, site is already in Dev mode -- so I'm really surprised it's not telling me anything more useful!

cheers
MIKE

ps Hmm, just switched code to Page.php -- same result : (

Avatar
mhdesign

Community Member, 206 Posts

31 May 2016 at 12:55pm

Hmm, just got weirder...

Had an error message flash across my screen telling me that Root.Content.Main is deprecated. I'm assuming that this refers to the GetCMSFields section of the code, this should now read Root.Main...

So I edited as follows:

<?php
/**
 * Defines the LandingPage page type
 */
 
class LandingPage extends EnquiryPage {
   static $db = array(
  );   
  static $has_one = array( 
     'Background' => 'Image' 
  );

function getCMSFields() {
		$fields = parent::getCMSFields();
		// add the upload control for the background image to the cms 
        $fields->addFieldToTab('Root.Main', new UploadField('Background')); 
		 return $fields;
	}
}

class LandingPage_Controller extends EnquiryPage_Controller {     
}

No more error. But there's no ''Background' tab either...