Does CodeIgniter support Namespace?
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
How To Get Namespaces to Work in Codeigniter
Actually, you can get namespaces to work in conjunction to relative paths in your application models. This modification makes loading models much easier and also allows you to have interfaces...
Add this to the end of your application/config/config.php
Example Namespaced Class:
Example Instantiation of Class in Your Code Somewhere:
IMPORTANT NOTE: DO NOT USE BUILT IN CI_Loader ( Ex: $this->load->model(); )
or alternatively on top of your PHP class (ex: controller, other model), you can do this...
Example of Interface:
You could check this out: yidas/codeigniter-psr4-autoload
The lib defines
app
as CI application root so that every classes in application could be loaded with PSR-4 namespace:Sample code for defining a class:
Namespace are supported by php and not by the framework (codeigniter in your case). If you use namespaces php version must be >= 5.3.0 Codeigniter dosen`t use namespaces because it is written to support php 4.