2

I get this error when I try to use autoload and namespaces. All my namespace classes are under app/libs/

16-Dec-2016 04:30:50 Europe/Berlin] PHP Fatal error:

Class 'App\libs\App' not found in /Users/mysite/app/page1.php on line 26

Here is My code:

require '../public/vendor/autoload.php';
use App\libs\App;
use App\libs\Auth;
    class Controller
     {
       public $app;
     public function __construct()
     {
        @set_exception_handler([$this, 'exceptionHandler']);
        $this->app       = new App();
     }

  }
1
  • I guess this is because the pathname and the classname are both App and that may be the issue.. Commented Dec 16, 2016 at 4:20

1 Answer 1

1

autoload normally includes files only under vendor folders. It does not load any other files, if you do not instructe to. You are probably using composer. if it is, you can add folders in composer.json file to include class files from other folders like App\libs. An example a composer.json file is:

{
    "require": {
        "twig/twig": "~1.0"
    },
    "autoload": {
        "psr-4": {
             "App\\": "App/"
        }
    }
}

In the examle above, it will autoload any files under App folder. Finally you need to run: composer dump-autoload to make this working.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.