# Integration of (new!) zend-console within MVC - does ist actually work?

**URL:** <https://discourse.laminas.dev/t/integration-of-new-zend-console-within-mvc-does-ist-actually-work/913>\
**Category:** Components & MVC\
**Created:** [January 22, 2019, 10:10pm UTC](https://discourse.laminas.dev/t/integration-of-new-zend-console-within-mvc-does-ist-actually-work/913 "2019-01-22T22:10:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![malwon](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/malwon/32/438_2.png) [@malwon](https://discourse.laminas.dev/u/malwon)\
**Post date:** [January 22, 2019, 10:10pm UTC](https://discourse.laminas.dev/t/integration-of-new-zend-console-within-mvc-does-ist-actually-work/913/1 "2019-01-22T22:10:05Z")

</div>

I understand **zend-mvc-console** is deprecated. Usage of **zend-console** is encouraged. According to the [official current docs](https://docs.zendframework.com/zend-console/intro/) MVC-integration is still possible. So I followed the docs and just added console config im my `module.config.php`:

```auto
return [
    'router' => [
        'routes' => [
            // HTTP routes are defined here
        ],
    ],

    'console' => [
        'router' => [
            'routes' => [
               'foo' => [
                    'options' => [
                        'route' => 'foo',
                        'defaults' => [
                            'controller' => Foo\Controller\Index::class,
                            'action' => 'index',
                        ],
                    ],
                ],
            ],
        ],
    ],

    /* ... */
];

```

However: Whatever I enter in the terminal (`$ php public/index.php foo` or just `$ php public/index.php`, `$ php7.2 public/index.php` doesn’t help either) it doesn’t matter index,php just always prints out HTML-Code into my terminal as if I would enter `http://localhost/fooapp/public/` (with successful Code 200) in my browser.

I’m really getting desperate, why doesn’t it work? What’s missing? Glad for **any** helpful hint or link.  
Thanks  
m.

---

<div class="post-metadata">

**Author:** ![guidofaecke](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/guidofaecke/32/427_2.png) [@guidofaecke](https://discourse.laminas.dev/u/guidofaecke)\
**Post date:** [January 23, 2019, 5:47am UTC](https://discourse.laminas.dev/t/integration-of-new-zend-console-within-mvc-does-ist-actually-work/913/2 "2019-01-23T05:47:34Z")

</div>

How does our index controller look like? Does your indexAction method include a ViewModel?  
Similar to this?

```auto
public function indexAction()
{
    return new ViewModel();
}

```

If yes, that’s why you see html.

Maybe try something along the line of

```php
public function indexAction()
{
    return "I am a CLI call";
}

```

---

<div class="post-metadata">

**Author:** ![malwon](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/malwon/32/438_2.png) [@malwon](https://discourse.laminas.dev/u/malwon)\
**Post date:** [January 23, 2019, 9:42am UTC](https://discourse.laminas.dev/t/integration-of-new-zend-console-within-mvc-does-ist-actually-work/913/3 "2019-01-23T09:42:38Z")

</div>

Thanks. I tried that.

But the problem seems to be a different one. According to the [docs on zend-console with MVC](https://docs.zendframework.com/zend-console/mvc/modules/), runing `$ php public/index.php` without any arguments or routes **on a terminal** should simply output the current Zend Framework version plus a failure reason:

 ![](https://yyz2.discourse-cdn.com/flex032/uploads/zendframework/original/1X/1379c8d3c637ec4cd8dc9029866eeb0be6f2863b.png)

I’ve got the impression ZF3 simply ignores my console config variables at `module.config.php`. For testing purposes I defined non existent controllers in the console config array, like this:

```auto
'console' => [
        'router' => [
            'routes' => [
                'default-route' => [
                    'type' => 'catchall',
                    'options' => [
                        'route' => '',
                        'defaults' => [
                            'controller' => 'xApplication\Controller\Index',
                            'action' => 'nonExistentAction',
                        ],
                    ],
                ],
                
                
                'foo' => [
                    'options' => [
                        'route' => 'foo bar',
                        'defaults' => [
                            'controller' => xxApplication\Controller\Index::class,
                            'action' => 'nonExistentAction',
                        ],
                    ],
                ],
            ],
        ],
    ],

```

Neither does ZF print out a failure reason as supposed nor is a fatal error triggered since I specified non existent controllers or actions.

Any ideas anybody?😭

---

<div class="post-metadata">

**Author:** ![guidofaecke](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/guidofaecke/32/427_2.png) [@guidofaecke](https://discourse.laminas.dev/u/guidofaecke)\
**Post date:** [January 24, 2019, 12:27am UTC](https://discourse.laminas.dev/t/integration-of-new-zend-console-within-mvc-does-ist-actually-work/913/4 "2019-01-24T00:27:00Z")

</div>

I know that’s not the answer you are looking for, but this github comment from MWOP is all I can dig up for you.

* * *

We have the following components related to console functionality:

- zendframework/zend-console provides an adapter-based approach for working with the console at a low-level.
- zendframework/zend-mvc-console provides bindings for using zend-mvc controllers to provide handlers for console purposes, using zendframework/zend-console.
- zfcampus/zf-console provides a console microframework for writing console application using zendframework/zend-console. (zfcampus is the organization where Apigility, our API builder and runtime, lives; zf-console was developed there as we had need for easier console tooling within that project.)

I hope that clears up where each of these packages lives and the purposes each serves.

Regardless, each of these is considered **deprecated**. Maintaining them requires too much effort, particularly when there are other solutions in this problem space.

---

<div class="post-metadata">

**Author:** ![malwon](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/malwon/32/438_2.png) [@malwon](https://discourse.laminas.dev/u/malwon)\
**Post date:** [January 25, 2019, 11:00am UTC](https://discourse.laminas.dev/t/integration-of-new-zend-console-within-mvc-does-ist-actually-work/913/5 "2019-01-25T11:00:06Z")

</div>

Thanks! This actually did help! 😀 Once I installed **zend-mvc-console** in addition to the already installed **zend-console** it just worked fine!  
Unfortunately the docs on **zend-console** don’t mention at all that you need to install **zend-mvc-console** in order to benefit fom MVC-Support for zend-console. Also, there is no hint about the deprecation thing. It would have saved me a lot of hassle if this would’ve been clearer in the official documentation! 🤨

Is there a way to suggest a correction of the documentation to Zend?

---

<div class="post-metadata">

**Author:** ![guidofaecke](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/guidofaecke/32/427_2.png) [@guidofaecke](https://discourse.laminas.dev/u/guidofaecke)\
**Post date:** [January 25, 2019, 2:00pm UTC](https://discourse.laminas.dev/t/integration-of-new-zend-console-within-mvc-does-ist-actually-work/913/6 "2019-01-25T14:00:47Z")

</div>

You are welcome to do so. The documentation can be found on GitHub. Clone it, make the changes and create a PR for it 🙂

---

<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:** [January 27, 2019, 9:34am UTC](https://discourse.laminas.dev/t/integration-of-new-zend-console-within-mvc-does-ist-actually-work/913/7 "2019-01-27T09:34:27Z")

</div>

See and add your comments:

> <https://github.com/zendframework/zend-console/pull/42>
