Jump to:

22976 Posts in 11493 Topics by 2824 members

General Questions

SilverStripe Forums » General Questions » [User Error] Bad class to singleton() - HomePage

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

Page: 1
Go to End
Author Topic: 5180 Views
  • slavelabourer
    Avatar
    Community Member
    25 Posts

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

    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

  • Willr
    Avatar
    Forum Moderator
    5462 Posts

    Re: [User Error] Bad class to singleton() - HomePage Link to this post

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

  • slavelabourer
    Avatar
    Community Member
    25 Posts

    Re: [User Error] Bad class to singleton() - HomePage Link to this post

    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.

  • inCharge
    Avatar
    Community Member
    102 Posts

    Re: [User Error] Bad class to singleton() - HomePage Link to this post

    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.

    5180 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.