Reputation: 21
I have a problem with accessing my Propel's classes.
For example, I try to access the Livre
class.
My code in index.php is :
use biblio\biblio\Livre;
//load Propel's autoload
require 'vendor/autoload.php';
$collect = new Livre();
$collect->setNom("Aventure");
$collect->save();
And the output error is :
Fatal error: Class 'biblio\biblio\Livre' not found in /Applications/MAMP/htdocs/propel/index.php on line 7
My classe Livre
is in the folder biblio/biblio/Livre.php
With this code, Eclipse finds my Livre
. But when PHP executes, there is an error.
Somebody have a solution ?
Upvotes: 1
Views: 104
Reputation: 20486
You're going to need to add something like this to your composer.json
file (obviously modifying this autoload
data into the entire JSON file, rather than just appending this as-is):
{
...
"autoload": {
"classmap": ["biblio/"]
}
}
Without this, require vendor/autoload.php;
won't include your Propel classes and PHP won't be able to find the namespace/class. Don't forget to run php composer dump-autoload
from your command line to update the autoload.php
file.
See the Propel documentation for more information:
After generating the classes, you have to autoload them.
Or, learn more about Composer's autoloading:
For libraries that specify autoload information, Composer generates a vendor/autoload.php file. You can simply include this file and you will get autoloading for free. [...] You can even add your own code to the autoloader by adding an autoload field to composer.json.
Upvotes: 1