no framework - PHP autoloading class not found -


let me first explain have done reach point. there tutorial on github called no-framework here https://github.com/patricklouys/no-framework-tutorial tutorial! have completed , wanting add more libraries. have composer setup autoloading , file looks this.

{ "name": "xxx/no-framework", "description": "no framework", "authors": [     {         "name": "xxx",         "email": "xxx@gmail.com"     } ], "require": {     "php": ">=5.5.0",     "filp/whoops": ">=1.1.2",     "patricklouys/http": ">=1.1.0",     "nikic/fast-route": "^0.7.0",     "rdlowrey/auryn": "^1.1",     "twig/twig": "~1.0",     "illuminate/database": "*" }, "autoload": {     "psr-4": {         "app\\": "src/"     } } 

}

and in src folder have made folder called models , in there books.php , in books.php have this

<?php     class book extends \illuminate\database\eloquent\model{         protected $table = 'books';     } 

and in bootstrap.php file i've included line after requiring composer autoloader

include('database.php'); 

the database.php file in src , looks this

<?php      use \illuminate\database\capsule\manager capsule;        $capsule = new capsule;       $capsule->addconnection(array(         'driver'    => 'mysql',         'host'      => 'localhost',         'database'  => 'test',         'username'  => 'test',         'password'  => 'l4m3p455w0rd!',         'charset'   => 'utf8',         'collation' => 'utf8_unicode_ci',         'prefix'    => ''     ));      $capsule->booteloquent(); 

and error. when try use book class trying use in 1 of controller this

<?php      namespace app\controllers;      use http\request;     use http\response;     use app\template\renderer;     use app\models\book book;       class pages{        private $request;        private $response;        private $renderer;         public function __construct(request $request, response $response, renderer $renderer){            $this->request = $request;            $this->response = $response;            $this->renderer = $renderer;        }         public function index(){           $book = new book;           $book->title = 'test';           $book->save();            $html = $this->renderer->render('index');           $this->response->setcontent($html);       }   } 

i error saying "class 'app\models\book' not found" i'm asuming im not autoloading correctly, alias thing there in composer.json or maybe else wrong idk. help? tutorial uses dependency injector library called auryn, maybe i'm missing in there? idk doubt though.

edit: if change use statement to include include('../src/models/book.php'); , put \ in front of class instantiation $book = new \book; , works, not right way.

i believe composer classmap merely tells system find files given class. php still needs know namespaces. pages in app\controllers namespace. book not given one, exist in global namespace @ \book. books.php (names of files match class contain, book.php) should include namespace declaration. suggest namepsace app\models;. change use statement use \book.

notice don't need alias it. it's book class you're using did request class can referenced last segment of it's namespaced designation.


Comments