PHPackages                             yidas/codeigniter-psr4-autoload - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. yidas/codeigniter-psr4-autoload

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

yidas/codeigniter-psr4-autoload
===============================

CodeIgniter 3 PSR-4 Autoloader for Application

2.0.0(6y ago)5419.5k—6.3%10[1 issues](https://github.com/yidas/codeigniter-psr4-autoload/issues)3MITPHPPHP &gt;=5.3.0

Since Feb 26Pushed 3y ago7 watchersCompare

[ Source](https://github.com/yidas/codeigniter-psr4-autoload)[ Packagist](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)[ Docs](https://github.com/yidas/codeigniter-psr4-autoload)[ RSS](/packages/yidas-codeigniter-psr4-autoload/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (3)

 [ ![](https://camo.githubusercontent.com/b1df5003f5bc21277aeb87c5d3558242b74eb54a61a253cc061a38c7a43bcac7/68747470733a2f2f75706c6f61642e77696b696d656469612e6f72672f77696b6970656469612f7a682f372f37632f436f646549676e697465722e706e67) ](https://codeigniter.com/)

CodeIgniter PSR-4 Autoload
==========================

[](#codeigniter-psr-4-autoload)

CodeIgniter 3 PSR-4 Autoloader for Application

[![Latest Stable Version](https://camo.githubusercontent.com/964a0bd97e42a00e0cb92817af0294ebe890a15b1a6aa555f975a06edd082935/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636f646569676e697465722d707372342d6175746f6c6f61642f762f737461626c653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)[![License](https://camo.githubusercontent.com/b41335a195786f36d4733e6cbc6f99d9e815a9ced0bb0fd6b17aa468c2797d3b/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636f646569676e697465722d707372342d6175746f6c6f61642f6c6963656e73653f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)[![Total Downloads](https://camo.githubusercontent.com/76890da5a253b8462c22fc0adff1177c1f2b775980bd7d154f9dc59498c85075/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636f646569676e697465722d707372342d6175746f6c6f61642f646f776e6c6f6164733f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)[![Monthly Downloads](https://camo.githubusercontent.com/ad38b1f7cf9f03f2145dfbb76d9f85036c702d915479bf163d19550c99e25405/68747470733a2f2f706f7365722e707567782e6f72672f79696461732f636f646569676e697465722d707372342d6175746f6c6f61642f642f6d6f6e74686c793f666f726d61743d666c61742d737175617265)](https://packagist.org/packages/yidas/codeigniter-psr4-autoload)

This PSR-4 extension is collected into [yidas/codeigniter-pack](https://github.com/yidas/codeigniter-pack) which is a complete solution for Codeigniter framework.

FEATURES
--------

[](#features)

- ***PSR-4 Namespace** support as Yii2 &amp; Laravel elegant patterns like*
- *Easy way to use **Interface, Trait, Abstract and Extending Class***
- ***Whole Codeigniter application** directory structure support*

---

OUTLINE
-------

[](#outline)

- [Demonstration](#demonstration)
- [Requirements](#requirements)
- [Installation](#installation)
- [Usage](#usage)
    - [Extending Class](#extending-class)
    - [Interface](#interface)
    - [Trait](#trait)
    - [Abstract](#abstract)
- [Conception](#conception)
- [Limitations](#limitations)

---

DEMONSTRATION
-------------

[](#demonstration)

By default, all PSR-4 namespace with `app` prefix in Codeigniter would relates to application directory.

- The class `/application/libraries/MemberService.php` could be called by:

```
new \app\libraries\MemberService;
```

- The class `/application/services/Process.php` with `static run()` method could be called by:

```
\app\services\Process::run();
```

- Enable to extend or implement classes with standard way:

```
class Blog_model extends app\models\BaseModel {}
class Blog extends app\components\BaseController {}
class Car implements app\contracts\CarInterface {}
```

---

REQUIREMENTS
------------

[](#requirements)

This library requires the following:

- PHP 5.3.0+
- CodeIgniter 3.0.0+

---

INSTALLATION
------------

[](#installation)

Run Composer in your Codeigniter project under the folder `\application`:

```
composer require yidas/codeigniter-psr4-autoload

```

Check Codeigniter `application/config/config.php`:

```
$config['composer_autoload'] = TRUE;
```

> You could customize the vendor path into `$config['composer_autoload']`

---

USAGE
-----

[](#usage)

After installation, the namespace prefix `app` is used for the current Codeigniter application directory.

### Static Class

[](#static-class)

Create a hepler with PSR-4 namespace with a new `helpers` folder under `application` directory, for eaxmple `\application\helpers\`:

```
