Home >Backend Development >PHP Tutorial >Can CodeIgniter use namespaces?
There seems to be no namespace section in the CodeIgniter document.
PS: How to use libraries loaded by composer in CodeIgniter.
There seems to be no namespace section in the CodeIgniter document.
PS: How to use libraries loaded by composer in CodeIgniter.
CI3 begins to support namespaces.
If you want to use Composer
you can change $config['composer_autoload'] = TRUE in the
config/config.php file;
this option can be changed to TRUE, the default is FALSE
Pay attention here. If you change it to TRUE, then CI will automatically load application/vendor/autoload.php
So, if your vendor
directory is in the root directory of your project, that is, at the same level as index.php
, then you You can use $config['composer_autoload'] = realpath(APPPATH . '../vendor/autoload.php');
to introduce Composer
No namespace means that the CI framework cannot use the namespace.
But you can use your own code.
If you want to use composer, you can add
<code>require __DIR__.'/vendor/autoload.php'; ...</code>
Remember to adjust the path yourself
PHP versions greater than 5.3 support namespaces, which has nothing to do with the framework.
You only need to use the use
keyword
<code class="php">//use 你的composer包的完全限定名 use Monolog\Logger; use Monolog\Handler\StreamHandler; class TestController { }</code>