php - How to autoload 'libraries' in laravel 4? -


i've created library folder in app folder add app libraries. i've updated app config file , composer.json autoload folder, when run command composer dump-autoload next error:

{"error":{"type":"symfony\\component\\debug\\exception\\fatalerrorexception","message":"class 'app\\libraries\\search\\searchserviceprovider' not found","file":"d:\\users\\miguel borges\\documents\\trabalhos\\tese\\portal\\bootstrap\\compiled.php","line":4130}}php fatal error: class 'app\libraries\search\searchserviceprovider' not found in d:\users\miguel borges\documents\trabalhos\tese\portal\bootstrap\compiled.php on line 4130 [finished in 1.1s exit code 255]

my app folder tree:

app | ... + libraries | + search | | - search.php | | - searchfacade.php | | - searchserviceprovider.php | + lib2 | | - ... | + lib3 | | - ... | | - theme.php | - ... - filters.php - routes.php 

searchserviceprovider.php

namespace app\libraries\search;  use illuminate\support\serviceprovider;  class searchserviceprovider extends serviceprovider {      /**      * register service provider.      *      * @return void      */     public function register()     {         $this->app['search'] = $this->app->share(function($app)         {             return new search;         });     }  } 

composer.json

    "autoload": {         "classmap": [             "app/commands",             "app/controllers",             "app/models",             "app/libraries",             "app/database/migrations",             "app/database/seeds",             "app/tests/testcase.php"         ]         // ,   //       "psr-0": {   //           "app": "app/libraries"   //       }     }, 

basically, need autoload libraries within 'libraries' folder.

you should create top-level namespace application.

then put libraries you code under namespace. note: third-party libraries should (hopefully) installed via composer , therefore have own namespace/autoloading setup.

your directory structure be:

libraries     myapp         search (note directory capitalized)             search.php             searchfacade.php             searchserviceprovider.php         anotherlib 

then classes follow namespace:

file: myapp/search/search.php:

<?php namespace myapp\search;  class search { ... } 

and finally, autoloading setup:

"autoload": {     "classmap": [         "app/commands",         "app/controllers",         "app/models",         "app/libraries",         "app/database/migrations",         "app/database/seeds",         "app/tests/testcase.php"     ]     ,     "psr-0": {          "myapp": "app/libraries"     } }, 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -