# How to inject custom php classes into zend directory

**URL:** <https://discourse.laminas.dev/t/how-to-inject-custom-php-classes-into-zend-directory/368>\
**Category:** Mezzio\
**Tags:** expressive, zend-mvc\
**Created:** [November 15, 2017, 2:29pm UTC](https://discourse.laminas.dev/t/how-to-inject-custom-php-classes-into-zend-directory/368 "2017-11-15T14:29:46Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![erfan](https://avatars.discourse-cdn.com/v4/letter/e/c4cdca/32.png) [@erfan](https://discourse.laminas.dev/u/erfan)\
**Post date:** [November 15, 2017, 2:29pm UTC](https://discourse.laminas.dev/t/how-to-inject-custom-php-classes-into-zend-directory/368/1 "2017-11-15T14:29:46Z")

</div>

hi. does anyone know how to insert custom php classes into zend framework 3 modular structure?!

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [November 15, 2017, 9:29pm UTC](https://discourse.laminas.dev/t/how-to-inject-custom-php-classes-into-zend-directory/368/2 "2017-11-15T21:29:38Z")

</div>

> [@erfan](#):
>
> does anyone know how to insert custom php classes into zend framework 3 modular structure?!

The module system of ZF2, ZF3 and zend-expressive is very flexible and simple. A module can contain (almost) everything.  
Look at the “[In-Depth tutorial](https://docs.zendframework.com/tutorials/in-depth-guide/first-module/)”, there will you find an example of a blog module. This module includes many “custom” classes.  
I hope this will help or do you mean something else?

---

<div class="post-metadata">

**Author:** ![erfan](https://avatars.discourse-cdn.com/v4/letter/e/c4cdca/32.png) [@erfan](https://discourse.laminas.dev/u/erfan)\
**Post date:** [November 16, 2017, 1:12pm UTC](https://discourse.laminas.dev/t/how-to-inject-custom-php-classes-into-zend-directory/368/3 "2017-11-16T13:12:04Z")

</div>

> [@froschdesign](#):
>
> do you mean something else

I have used some custom classes in my document and for the record I studied blog module, but I had to include the classes. i am wondering if there is a way to address the desired custom class like in the zend plugins.

---

<div class="post-metadata">

**Author:** ![merkushin](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/merkushin/32/234_2.png) [@merkushin](https://discourse.laminas.dev/u/merkushin)\
**Post date:** [November 16, 2017, 1:14pm UTC](https://discourse.laminas.dev/t/how-to-inject-custom-php-classes-into-zend-directory/368/4 "2017-11-16T13:14:57Z")

</div>

May be you just need to define autoload rules in composer.json for your namespace?  
Here is simple example:

```
"autoload": {
  "psr-4": {
    “AppNs\\ModuleNs\\”: "module/ModuleNs/src"
  }
},
"autoload-dev": {
  "psr-4": {
    “AppNs\\ModuleNs\\”: [
      "module/ModuleNs/test/functional",
      "module/ModuleNs/test/unit"
    ]
  }
},
```

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [November 16, 2017, 9:03pm UTC](https://discourse.laminas.dev/t/how-to-inject-custom-php-classes-into-zend-directory/368/5 "2017-11-16T21:03:59Z")

</div>

> [@erfan](#):
>
> i am wondering if there is a way to address the desired custom class like in the zend plugins.

Please see in the [tutorial](https://docs.zendframework.com/tutorials/in-depth-guide/first-module/#writing-a-new-module) or in the comment from @merkushin, because the autoloading is done by Composer. (More background infos here: [Basic usage - Composer](https://getcomposer.org/doc/01-basic-usage.md#autoloading))  
That’s all!
