Namespace in PHP CodeIgniter Framework

后端 未结 4 1506
温柔的废话
温柔的废话 2020-11-28 09:32

Does CodeIgniter support Namespace?

4条回答
  •  萌比男神i
    2020-11-28 10:17

    Just a simple psr-4 autoloading and you are done.

    In the config/config.php load composer using

    $config['composer_autoload'] = FCPATH.'vendor/autoload.php';
    

    In the root directory run composer install In the generated composer.json add following lines for psr4 autoloading.

        "autoload": {
            "psr-4": {
                "App\\": "application/"
            }
        },  
    

    App would be your namespace in this case.

    Example: suppose you have a class Service in libraries folder. You can namespace it with:

    Use it in Welcome controller class:

提交回复
热议问题