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

7

23

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)

Jackstraws answered 19/8, 2013 at 11:29 Comment(4)
I have done it in Composer/bin by cmd... dir=$(d=$(dirname "$0"); cd "$d" $$ pwd) if command -v 'cygpath' >/dev/null 2>&1; then dir=$(cygpath -m $dir); fi dir=$(echo $dir | sed 's/ /\ /g') php "${dir}/composer.phar" $* –Lamartine
Have you tried to include the file autoload.php in a relative way from where you need?Jodhpurs
I tried it, and like I said, I said that autoload.php not find the file, but if I leave only the "use" tells me that tells me I can not find the Validator class.Lamartine
You need to require_once('../../../../vendor/autoload.php'). In this way include the file you need.Jodhpurs
J
20

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
Jodhpurs answered 19/8, 2013 at 13:46 Comment(0)
O
24

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

Orazio answered 19/8, 2013 at 11:31 Comment(0)
J
20

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
Jodhpurs answered 19/8, 2013 at 13:46 Comment(0)
L
8

I did this. i checked the file and permissions as always but everything looks ok. Then I open autoload.php and see ... oh! we have __DIR__ ofcourse.

I was doing this

require '../../vendor.autoload.php';

Changed to

require __DIR__.'../../vendor.autoload.php';

Not politically correct but got me by the frustrating waste of time for the moment.

ofcourse there are better alternatives to __DIR__ like using a BASE Path etc. But this worked for me.

Lowerclassman answered 7/2, 2014 at 18:22 Comment(1)
2016...also I moved to python. :PLowerclassman
C
0

I had the same issue with xampp. I installed composer and used:

composer create-project --stability=dev --prefer-dist yiisoft/yii2-app-basic D:\xampp\htdocs\newapp

My issue solved now.

Chenoweth answered 4/1, 2016 at 7:0 Comment(0)
I
-1

I had the same problem and i solved it by using the last version of laravel, just try this code to create your project:

composer create-project laravel/laravel exampleProject --prefer-dist

this always uses the last version.

Informal answered 2/7, 2016 at 15:34 Comment(0)
D
-1

I solved simple re-run composer update from the project Root. (my case was on Magento2, but the error and the path are the same)

Dwt answered 5/9, 2016 at 9:43 Comment(0)
I
-1

In my case i simple forgot to change my working directory before running the command composer require cboden/ratchet in cmd this fixed it cd c:\path to project\ then composer require cboden/ratchet

Iselaisenberg answered 30/4, 2017 at 17:18 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.