A class should be in a 'classes' folder. Then the autoloader can find it and load it, no need for manual loading. In PKGPATH (which is the root of installed packages) is definitely a bad idea.
You get that error because tasks are defined in the Fuel\Tasks namespace, and since you try to instantiate a class without specifying the namespace, PHP will try to find it in the current namespace.
thanks for your answer. To completelly understand, I have to move my airship.php file, which containt the Urbanairship class in the APP/CLASSES/airship.php
Inside the class I have to add his own namespace, lets say :
namespace Airship;
Then inside my task I have to call the class like this -.
$message = new Airship\Urbanairship;
It's correct, because I've tried and it doesn't work.
The only solution till now was to :
1. wrote inside my Urbanairship class the line namespace Fuel\Tasks; 2. to includethe class in my task file : include airship.php; 3. call it normally $message = new Urbanairship;
Please let me understand the correct way to do the job, because I want to use the class from a task, but also from a controller.
FuelPHP rules say that: - all classes go into the classes folder (for app, modules and packages) - the combination of namespace and classname should map uniquely to a file - packages and modules have a base namespace equal to the package or module name
The mapping works as follows: if the namespace location is known (i.e. it's a package or a module, that will select the prime location of the classes folder). That namespace is then stripped. If not, it defaults to app/classes. The remainder (any remaining namespaces and the class name) are glued together using a directory separator, and then all backslashes and underscores are replaced by directory separators.
So, if you have a namespace "Airship" and a classname "Urbanairship", it can be in: - app/modules/airship/classes/urbanairship.php (if airship is a module) - packages/airship/classes/urbanairship.php (if airship is a package) - app/classes/airship/urbanairship.php
If your class would be called "Urban_Airship", it would be: - app/modules/airship/classes/urban/airship.php (if airship is a module) - packages/airship/classes/urban/airship.php (if airship is a package) - app/classes/airship/urban/airship.php
If you deviate from this rule, the autoloader won't be able to load it without help. If you have to deviate from it (which is not recommended but sometimes needed, for example because it's a third-party class), you can tell the autoloader it exists, and where to find it, in your app/bootstrap.php:
So you define the fully namespaced classname, and tell the autoloader which file defines this class. You can do the same in a package bootstrap. You can not do this for modules.