php - How can I load a library in Codeigniter via autoload composer? -


i have installed autoload via composer in codeigniter , tested if file autoload.php included , it's. so, if have library called pager in libraries, how can instantiate (load) pager class? it's fresh codeigniter installation, version 3.1.2

i set in config this:

$config['composer_autoload'] = true; 

i have try following ways in welcome controller:

$pager = new libraries\pager();  //class 'libraries\pager' not found  $pager = new \libraries\pager(); //class 'libraries\pager' not found $pager = new \library\pager();   // class 'library\pager' not found $pager = new pager();            // class 'library\pager' not found 

and here pager class libraries directory:

class pager  {      function __construct()     {         parent::__construct();         echo __class__;     }  } 

thank help!

this in fact unrelated codeigniter.

you need tell composer have own php classes aren't among autoloaded files.

in composer.json add 1 of these:

{     // ...     "autoload": {         "psr-4": { "mynamespace\\": "src/library/mynamespace" },         "files": ["src/some/custom/filepath.php"]     } } 

then run in console update update autoload.php new config:

$ composer update 

now every time use class mynamespace such mynamespace\myclass it'll file src/library/mynamespace/myclass.php.
also, file src/some/custom/filepath.php included automatically don't need include manually. (i don't know what's usecase).

see more info: https://getcomposer.org/doc/04-schema.md#autoload


Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -