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

[User Error] Bad class to singleton() - HomePage


Reply


4 Posts   5475 Views

Avatar
slavelabourer

Community Member, 25 Posts

28 April 2009 at 11:07pm

Hi, just playing with silverstripe for the first time, hoping that this is a typical newbie problem, but am struggling to find resources for specific errors. Hope someone can help thanks for your time.

Dan.

Problem occurs when flushing the database after creating the homepage.php in tutorial 1.

Building Database

Creating database tables
# PageComment
# SiteTree
# Field SiteTree.ClassName: changed to enum('SiteTree','Page','GhostPage','HomePage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree' (from enum('SiteTree','Page','GhostPage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree')
# Field SiteTree_Live.ClassName: changed to enum('SiteTree','Page','GhostPage','HomePage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree' (from enum('SiteTree','Page','GhostPage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree')
# Field SiteTree_versions.ClassName: changed to enum('SiteTree','Page','GhostPage','HomePage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree' (from enum('SiteTree','Page','GhostPage','ErrorPage','RedirectorPage','VirtualPage') character set utf8 collate utf8_general_ci default 'SiteTree')
# Email_BounceRecord
# QueuedEmail
# File
# Group
# LoginAttempt
# Member
# MemberPassword
# Permission
# Widget
# WidgetArea
# Page
# GhostPage
# ErrorPage
# RedirectorPage
# VirtualPage
# Image
# Folder
# Image_Cached

Creating database records
# PageComment
# SiteTree
[User Error] Bad class to singleton() - HomePage
GET /silver/SilverStripe/dev/build?flush=1

Line 263 in /home/digitalp/public_html/silver/SilverStripe/sapphire/core/Core.php
Source

254    if(($pos = strpos($className,'_')) !== false) $className = substr($className,0,$pos);
255    if($_CLASS_MANIFEST[$className]) return $_CLASS_MANIFEST[$className];
256 }
257
258 function singleton($className) {
259    static $_SINGLETONS;
260    if(!isset($className)) user_error("singleton() Called without a class", E_USER_ERROR);
261    if(!is_string($className)) user_error("singleton() passed bad class_name: " . var_export($className,true), E_USER_ERROR);
262    if(!isset($_SINGLETONS[$className])) {
263     if(!class_exists($className)) user_error("Bad class to singleton() - $className", E_USER_ERROR);
264       $_SINGLETONS[$className] = Object::strong_create($className,null, true);
265       if(!$_SINGLETONS[$className]) user_error("singleton() Unknown class '$className'", E_USER_ERROR);
266    }
267    return $_SINGLETONS[$className];
268 }
269

Trace

* Bad class to singleton() - HomePage
Line 263 of Core.php
* singleton(HomePage)
Line 1867 of DataObject.php
* DataObject::has_own_table(HomePage)
Line 89 of ClassInfo.php
* ClassInfo::dataClassesFor(SiteTree)
Line 2109 of DataObject.php
* DataObject->buildSQL(URLSegment = 'home')
Line 2366 of DataObject.php
* DataObject->instance_get_one(URLSegment = 'home',)
Line 2320 of DataObject.php
* DataObject::get_one(SiteTree,URLSegment = 'home')
Line 925 of SiteTree.php
* SiteTree->requireDefaultRecords()
Line 210 of DatabaseAdmin.php
* DatabaseAdmin->doBuild(,1)
Line 100 of DatabaseAdmin.php
* DatabaseAdmin->build()
Line 130 of DevelopmentAdmin.php
* DevelopmentAdmin->build(HTTPRequest)
Line 107 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 115 of main.php

Avatar
Willr

Forum Moderator, 5513 Posts

30 April 2009 at 10:13pm

Make sure your file is HomePage.php - note the case and the class inside it - class HomePage extends Page { ...

Avatar
slavelabourer

Community Member, 25 Posts

1 May 2009 at 1:56am

Ah cool thanks, i did figure that out after a while. Just making the move from .NET where casing didn't matter, gonna have to cleanup those bad habits. You can mark as solved.

Cheers,
Dan.

Avatar
inCharge

Community Member, 102 Posts

16 May 2011 at 3:26am

If fixing the case doesn't work, try clearing the SilverStripe cache as well.

I had the same 'Bad class to singleton' message. I was delighted to find this post, and Will was right, coincidentally I had a file of the same name as the original post, but one of the files was Homepage instead of HomePage. Imagine my disappointment when after fixing the case, the problem continued. Another post suggested emptying the silverstripe-cache folder, and that worked. Maybe ?flush=all would have done the trick.

The disconnection between SilverStripe error messages and their causes can make working with SilverStripe tough going, especially for beginners. If you're one of those, keep persevering; the benefits well outweigh the disadvantages. But if SilverStripe error messages could be improved, the uptake would be much better.