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.

DataObjectManager Module /

Discuss the DataObjectManager module, and the related ImageGallery module.

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

Extend Member class using dataobjectdecorator ERROR


Go to End


4 Posts   2638 Views

Avatar
McBainVT

Community Member, 5 Posts

14 September 2009 at 9:31am

I have read through a bunch of the posts on this forum and all of the documentation I can find but I can't figure out how to add a few fields to the member class. I have tried using the dataobjectdecorator to do this, but I get this error when /dev/build the website. I am in dev mode currently if that matters. I am also using the most current version of silverstripe 2.3.2 and I do have dataobject_manager module successfully added/installed.

[Notice] Undefined variable: _SESSION
GET /samplebusiness/dev/build

Line 120 in /home/mcshane1/public_html/samplebusiness/sapphire/core/control/Director.php

Source

111 			@file_get_contents('php://input')
112 		);
113 		
114 		// @todo find better way to extract HTTP headers
115 		if(isset($_SERVER['HTTP_ACCEPT'])) $req->addHeader("Accept", $_SERVER['HTTP_ACCEPT']);
116 		if(isset($_SERVER['CONTENT_TYPE'])) $req->addHeader("Content-Type", $_SERVER['CONTENT_TYPE']);
117 		if(isset($_SERVER['HTTP_REFERER'])) $req->addHeader("Referer", $_SERVER['HTTP_REFERER']);
118 
119 		// Load the session into the controller
120 		$session = new Session($_SESSION);
121 		$result = Director::handleRequest($req, $session);
122 		$session->inst_save();
123 
124 		// Return code for a redirection request
125 		if(is_string($result) && substr($result,0,9) == 'redirect:') {
126 			$response = new HTTPResponse();

Trace

    * Director::direct(/dev/build)
      Line 118 of main.php

Line 120 shows up in red, so that must be what the error is?

The site does function after displaying that error but whenever I try to login it just redirects me back security/login screen, even though I have entered the correct email and password. I don't have the same problem and login works perfectly when I am not attempting to use dataobjectdecorator.

Here is the code I am using for my memberdecorator file.

class MemberDecorator extends DataObjectDecorator { 

function augmentSQL(SQLQuery &$query) {}
    
   	public function extraStatics() { 
	
      return array( 
         'db' => array( 
            "Website" => "Text",
		"Username" => "Text",		
         ), 
         'has_one' => array( 
            "Avatar" => "Image",
         ), 
      ); 
   } 
   
   	public function getCMSFields() {
   		$this->extend('updateCMSFields', $fields);
   		return $fields;
	}
    
   	public function updateCMSFields(FieldSet &$fields) { 
    	$fields->push(new TextField("Username", "Username"), 'Members'); 
		$fields->push(new TextField("Website", "Website URL"), 'Members'); 
    	$fields->push(new ImageField("Avatar", "Profile Image"), 'Members'); 
   }    
} 

Can anyone please tell me if there are any errors in the file, with all the old and outdated info I have seen in the docs it is quite possible I am using some out of date methods that no longer work with this silverstripe version. Any help would be greatly appreciated.

Avatar
UncleCheese

Forum Moderator, 4102 Posts

16 September 2009 at 2:00am

That error is almost always due to outputting to the browser before headers are sent. Make sure you don't have any echo, var_dump, or other debugging statements kicking around. That will often trip up the page load.

Avatar
McBainVT

Community Member, 5 Posts

16 September 2009 at 4:45am

Yea it does appear to kick out that same error, no matter what I am putting in the memberdecorator file. I looked around through all my files but there isn't any echo statements, var_dump, or anything I could see that would output to the browser before the headers are sent.

Do you have any idea if there is any place or file that causes this error typically?

I am succussfully using dataobjectdecorator for 'Groups', it only throws this error when I am attempting to use dataobjectdecorator for the member class, dunno if that information is useful or not.

Avatar
McBainVT

Community Member, 5 Posts

16 September 2009 at 5:03am

Nevermind figured it out. Had a space after php close tag in memberdecorator. thank you for your help uncle cheese, I am new to silverstripe and was assuming my error was caused by me not knowing how to correctly use the dataobjectdecorator but apparently it was just that space, works fine now.