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

assets error b/o class named folder


Reply


6 Posts   1598 Views

Avatar
yurigoul

Community Member, 202 Posts

4 November 2009 at 12:28am

I already solved the problem, but it brings back a question about naming conventions:

I created a class named 'folder extends Page' with a nice folder icon in order to store some pages there that are not visible in the site directly (footer-content etc). And then I ran into the following error when accessing assets in the backend:

[User Error] Couldn't run query: SELECT `File`.*, `File`.ID, if(`File`.ClassName,`File`.ClassName,'File') AS RecordClassName FROM `File` WHERE (`SiteTree`.`ID` = 1) AND (`File`.ClassName IN ('Folder')) ORDER BY Name LIMIT 1 Unknown column 'SiteTree.ID' in 'where clause'
GET /_s/admin/assets/

Line 401 in /Users/yurigoul/Sites/_s/sapphire/core/model/MySQLDatabase.php

Removing the folder-class and giving a dev/build removes the problem.

Here is my folder-class for those who are in doubt (and my file in ./mysite/code was called folder.php):

<?php
class folder extends Page {
static $db = array(
   );
public static $has_one = array(
   );
   static $icon = "themes/annomedia/images/icons/folder";
}

class folder_Controller extends Page_Controller {
   public function init() {
      parent::init();

   }
}
?>

Also my question is: what names should I not use, or what else did I do wrong?

Avatar
ajshort

Community Member, 244 Posts

4 November 2009 at 1:12am

SilverStripe already has a Folder class in the core. By creating your own you are effectively override it, which leads to errors as yours would conflict and has wildly different functionality.

Avatar
yurigoul

Community Member, 202 Posts

4 November 2009 at 1:22am

Exactly what I was thinking, but the real question is: what are names I should not use for classes. I could not find a list or so. Or is the general guideline I should use Page at the end of every class name?

Another thing is that I used 'folder' with a lowercase and the error is because of a class named 'Folder' with uppercase.

Avatar
ajshort

Community Member, 244 Posts

4 November 2009 at 9:35am

That is one way to get around it. Also, PHP is case insensitive except for variable names.

Avatar
rbquirke

Community Member, 70 Posts

4 November 2009 at 12:28pm

As a convention, I generally use whatever my project name is as the start of my custom classes to avoid conflict so:
AcmeRecruitFolder
AcmeRecruitAdmin

etc

This avoids your problem without trying to consult a list of possible classes already in use.

Avatar
yurigoul

Community Member, 202 Posts

4 November 2009 at 10:21pm

Thanks for the answers.

But the main reason why I ask this question - and in the future I might be asking similar questions - is because I have this sense that certain things are missing from the manual section. I have the feeling that the manual section contains just enough to get you going, but certain very important details are very hard to find.

One of the reasons is that the search function in doc.silverstripe.org is really bad: if you for instance search for DataObject::get I am under the impression you get a result for 'dataobject' OR 'get'

Another reason is that a lot of items are just place holders with links to the api page. This might work for experienced programmers and for people who are working with the cms a long time, but for someone whose main interest is creating themes it is hard to get a firm grip on the subject. Sometimes there are even links to nonexistant items, like http://doc.silverstripe.org/doku.php?id=silverstripe-tutorial or http://doc.silverstripe.com/doku.php?id=devmode. Thes links come up during the install. (I will make a ticket for these)

And in general I think it is a good thing there are a bunch of links in the index of doc.silverstripe.com, but I have the feeling it could be better and that it is incomplete.

I might be volunteering to do something in that section, but not before I have a better insight in the material. Hence a question like this.

Thank you for your time :-)