Can CodeIgniter use namespaces?

Source: Internet
Author: User
The CodeIgniter document does not seem to contain namespace. PS: How to use the library loaded by composer in CodeIgniter. The CodeIgniter document does not seem to contain namespace.
PS: How to use the library loaded by composer in CodeIgniter.

Reply content:

The CodeIgniter document does not seem to contain namespace.
PS: How to use the library loaded by composer in CodeIgniter.

CI3 began to support namespaces.
If you want to useComposerYou canconfig/config.phpFile$config['composer_autoload'] = TRUE;This option is changed to TRUE. the default value is FALSE.

Note. If you change it to TRUE, the CI is automatically loaded.application/vendor/autoload.phpSo, if yourvendorThe directory is under the root directory of your project, that isindex.phpSame level, you can use$config['composer_autoload'] = realpath(APPPATH . '../vendor/autoload.php');This way to introduceComposer

Without namespace, the CI framework cannot use namespaces.
But you can use your own code.
If you want to use composer, you can add

require __DIR__.'/vendor/autoload.php';...

Remember to tune the path yourself

If php version is later than 5.3, the namespace is supported. it has nothing to do with the framework.
You only need to useuseKeywords

// Use the fully qualified name of your composer package use Monolog \ Logger; use Monolog \ Handler \ StreamHandler; class TestController {}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.