Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Include a normal class
  • I'm about ready to pull my hair out trying to figure out why I can't include a normal class!!!!!!!!!!
    I created a class called 'HtmlParser' and placed it in my 'Classes' directory.
    When I call new HtmlParser(); I get the following error: ErrorException [ Error ]: Class 'HtmlParser' not found

    I thought FuelPHP was suppose to automatically load any class on usage?

    I've tried to manually load the class as well using Fuel::load('HtmlParser.php'); as well with no luck. That tells me the file is not found.
  • Yes, it does. But this class doesn't follow the coding standards rules, which says that classnames MUST be ucfirst(). Also, all filenames in FuelPHP MUST be lower case.

    If you insist on using this non-standard name, you'll have to tell the autoloader that this class exists, and where to load it from. In your app/bootstrap.ini, add

    Autoloader::add_classes(array(
        'HtmlParser' => APPPATH.'classes/HtmlParser.php',
    ));

    So it knows where to find it.

    These rules are so strict to limit the number of file_exists() calls, which are very expensive and have quite an impact on the performance of the framework. If it has to check all possible permutations of class and filename case, the number of calls would go through the roof...
  • I tried the naming thing and that didn't work, but the Autoloader bit did. Still not sure why it's not autoloading though.

    Thanks
  • The autoloader requires a class named "Htmlparser", in a file called APPPATH.'classes/htmlparser.php'. If you have done it like that, I wouldn't know why it didn't work. That works fine here.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion