Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why my autoload.php of composer doesn't work?

Tags:

I have a project, I use Composer and i import many thing by it... i require the autoload.php in my index (the root of project) and istead Slim, Mongo, Twig work very well. But when I call a class of Respect/Validation it doens't work; if I simply use Respect/Validation the error is:

Class 'Respect\Validation\Validator' not found in (path of file when i need it).

if I try to require also here the autoload.php the errors are:

**Warning**: require_once(vendor/autoload.php): failed to open stream: No such file or directory in (path of file when i need it)

**Fatal error**: require_once(): Failed opening required 'vendor/autoload.php' (include_path='.;C:\xampp\php\PEAR') in (path of file when i need it)

like image 514
Matteo Calò Avatar asked Aug 19 '13 11:08

Matteo Calò


People also ask

How do I use autoload in composer?

After you create the composer. json file in your project root with the above contents, you just need to run the composer dump-autoload command to create the necessary autoloader files. These will be created under the vendor directory. Finally, you need to include the require 'vendor/autoload.

How do you autoload in PHP?

The spl_autoload_register() function registers any number of autoloaders, enabling for classes and interfaces to be automatically loaded if they are currently not defined. By registering autoloaders, PHP is given a last chance to load the class or interface before it fails with an error.

What is autoload file PHP?

Autoloading means the automatic loading of the files required for your project/application. That is including the files required for your application without explicitly including it with include() or require() functions.

What is autoload PHP in laravel?

Auto-Loading allows you to load class files when they are needed without explicitly loading or including them. This gives you ease in running your application by loading those files automatically which are needed every time. Laravel is built to work with Composer.


2 Answers

Try using php composer dump-autoload. It may fix that problem.

like image 163
ciruvan Avatar answered Oct 08 '22 20:10

ciruvan


If you are using a file (file.php) in a particular directory like this:

/app/controller/validation 

and your vendor directory is in the base path of the project, you need to include the relative path to vendor directory:

../../../vendor/autoload.php 
like image 29
Davide Pastore Avatar answered Oct 08 '22 21:10

Davide Pastore