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.

General Questions /

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

Undefined variable: _SESSION when calling a new method


Go to End
Reply


9 Posts   3078 Views

Avatar
TotalNet

Community Member, 181 Posts

3 March 2010 at 2:49pm

Okay, so I've been scratching my head over this one for the last couple of hours now and getting nowhere.

I've added a method to the Product_Image class to set the image sizes from an array in _config.php which works a treat using default values but as soon as I call the method from _config.php I get the _SESSION error.

It's nothing to do with the code within the function as I've removed it and it still generates the same error.

Here's the code in the hope someone can point out what is bound to be an obvious ommission

_config.php

Product_Image::set_productImageConfig(array('paddingBgColor' => 'ff0000'));

product.php

class Product_Image extends Image {
...
protected static $productImageConfig = array(
"paddingBgColor" => "ffffff",
"thumbnailWidth" => "150",
"thumbnailHeight" => "100",
"thumbnailQuality" => "80",
"contentImageWidth" => "150",
"contentImageQuality" => "90",
"largeImageWidth" => "500",
"largeImageQuality" => "90"
);
...
public static function set_productImageConfig($config) {
if (is_Array($config)) {
foreach ($config as $k => $v) {
if (array_key_exists ($k, self::$productImageConfig) && !is_null($v)) {
self::$productImageConfig[$k] = $v;
}
}
}
}
...
}

Avatar
carlos

Community Member, 41 Posts

3 March 2010 at 4:33pm

Hi,

I've tried you code and it works fine for me, maybe it's something you are doing after assign values to that array.

cheers

Avatar
TotalNet

Community Member, 181 Posts

3 March 2010 at 4:44pm

Thanks Carlos

Well, if I put the site into "Live" mode then the site displays and the function itself works but I can't log in - the _SESSION error is still present in the background.

I tried moving the code to the Product class making the static pulic and referencing it directly from the image class but that made no difference.

I have now moved the code to a new class (and .php file in mysite/code) and that's working now but, I wanted to get it working in the Procuct_Image class with the hope that it would make it in there officially.

Is this error caused by some formatting problem with the file itself perhaps? Maybe PhpED has screwed up the encoding or something?

Cheers,

Rich

Avatar
TotalNet

Community Member, 181 Posts

4 March 2010 at 11:15am

This is getting frustrating now :(

Getting the same error just trying to add a decorator, tried a simple one first, just decorating the Page class with the same result as soon as I add DataObject::add_extension to _config.php.

Trouble is, this error doesn't give me any idea where to start looking for issues, is it an environmental thing? is there one file with an issue that only shows under certain conditions?

If anyone has ideas on where to start looking I'd appreciate it, in the mean time I'll try another installation, v2.3.4 perhaps.

Cheers,

Rich

Avatar
TotalNet

Community Member, 181 Posts

4 March 2010 at 3:18pm

Edited: 04/03/2010 3:22pm

Thought I had a solution there for a minute, but no. can't delete my post.

Avatar
ajshort

Community Member, 244 Posts

4 March 2010 at 4:20pm

This is often caused by whitespace after a closing PHP tag. Do you have a closing PHP tag in Product.php, and does it have whitespace after it? If so, that could cause the issue. I would reccomend removing all closing tags from your site code since they're optional anyway and can cause issues like this which are hard to diagnose.

Avatar
TotalNet

Community Member, 181 Posts

4 March 2010 at 4:29pm

Thanks for the reply, I'd read that in one of the other threads about this error and have checked where ever I could.

It's now fixed though, for now ;)
I comapred with an environment that worked and it seems there was something about my page.php it didn't like, no idea what but it's behaving properly now so I'm happy.

Cheers,

Rich

Avatar
smix

Community Member, 1 Post

10 May 2010 at 11:40pm

I also had this problem and the cause was the encoding of the _config.php file. I had it set to UTF8 encoding (using Notepad++), when I changed it back to ANSI this error disappeared!

Go to Top