Class not found exception - Making a Helper on Koh

2019-05-10 12:43发布

问题:

got a fresh install of Kohana 3.1. Trying to make my own helpers. I have created a helper in the application/classes/helpers/ directory. I have called the file javascript.php, the class is called Helper_Javascript and has a static function that just returns "alert('sometext')" here it is

class Helper_Javascript {
    public static function alert($message)
    {
        return "alert('$message');\n";
    }
}

The problem is in my view or controller when I try to use the helper i just kepp getting the Class not found exception. I have tried to call it via <?php echo Helper_Javascript::alert('asdf');?> but get:

ErrorException [ Fatal Error ]: Class 'Helper_Javascript' not found. 

Please help, I have tried to read the docs for this at http://www.dealtaker.com/blog/2010/03/26/kohana-php-3-0-ko3-tutorial-part-7/ but it doesnt work.

You can see my view here: http://nabilboag.dyndns.org/simplysweet/

回答1:

The "_" in the class name is used to represent the directory structure. You have the rename the directory "helpers" into "helper": application/classes/helper/