# Trouble getting started with laminas-cli and mvc app

**URL:** <https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673>\
**Category:** Components & MVC\
**Tags:** laminas-cli\
**Created:** [June 15, 2020, 9:02pm UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673 "2020-06-15T21:02:58Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidmintz](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/davidmintz/32/213_2.png) [@davidmintz](https://discourse.laminas.dev/u/davidmintz)\
**Post date:** [June 15, 2020, 9:02pm UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673/1 "2020-06-15T21:02:58Z")

</div>

I’ve read the instructions but clearly I’m missing something. I installed laminas-cli via composer as instructed. Then I created this config and put it in `config/autoload/laminas-cli.global.php`:

```php
<?php
return [
    'laminas-cli' => [
        'commands' => [
            'admin:test' => \InterpretersOffice\Admin\Service\TestCommand::class,
        ],
    ],
];

```

and confirmed that this config was being read.

Then I created a `module/Admin/src/Service/TestCommand.php`:

```php
<?php
namespace InterpretersOffice\Admin\Service;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class TestCommand extends Command {
    public function configure()
    {

    }
    public function execute(InputInterface $input, OutputInterface $output)
    {
        $io = new SymfonyStyle($input,$output);
        $io->success("Test has succeeded.");
        return 0;
    }
}

```

and I confirmed that the composer’s autoloader was able to load it. Then I said:

```
vendor/bin/laminas admin:test

```

and got

```
The command "admin:test" does not exist.

```

and I can’t say I’m surprised. It feels like I’m missing a step or two but haven’t been able to figure it out.

btw I’ve read [this thread about setting up cli](https://discourse.laminas.dev/t/how-to-launch-a-basic-php-cli/1473) more than once and have considered trying some of that advice, but I thought maybe the laminas-cli does some of that for us.

Thanks.

---

<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:** [June 16, 2020, 5:59am UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673/2 "2020-06-16T05:59:12Z")

</div>

I didn’t look at your code, but please remember: at the moment laminas-cli is under development and so far there is [no release](https://github.com/laminas/laminas-cli/releases). It is therefore possible that not everything works as described or the description itself is incorrect.

---

<div class="post-metadata">

**Author:** ![davidmintz](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/davidmintz/32/213_2.png) [@davidmintz](https://discourse.laminas.dev/u/davidmintz)\
**Post date:** [June 16, 2020, 5:07pm UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673/3 "2020-06-16T17:07:44Z")

</div>

Ah, OK thanks. That would explain 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:** [June 16, 2020, 5:52pm UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673/4 "2020-06-16T17:52:08Z")

</div>

You can test version 0.1.0 now:

> **[laminas/laminas-cli](https://github.com/laminas/laminas-cli/releases/tag/0.1.0)**
>
> Console command runner, exposing commands written in Laminas MVC and Mezzio components and applications - laminas/laminas-cli

---

<div class="post-metadata">

**Author:** ![george](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/george/32/676_2.png) [@george](https://discourse.laminas.dev/u/george)\
**Post date:** [June 17, 2020, 8:53pm UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673/5 "2020-06-17T20:53:17Z")

</div>

Did you make a factory for the command? or add it to ‘invokables’?

```auto
return [
  'invokables' => [
    Command::class => Command::class,
  ],
];
```

---

<div class="post-metadata">

**Author:** ![davidmintz](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/davidmintz/32/213_2.png) [@davidmintz](https://discourse.laminas.dev/u/davidmintz)\
**Post date:** [June 17, 2020, 9:31pm UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673/6 "2020-06-17T21:31:42Z")

</div>

Yes, sort of — it looks like I omitted something from the snippets I put in the original post. The config I have is

```php
<?php
return [

    'laminas-cli' => [
        'commands' => [
            'admin:test' => InterpretersOffice\Admin\Service\TestCommand::class,

        ],
    ],
    'dependencies' => [
        'invokables' => [
            InterpretersOffice\Admin\Service\TestCommand::class => InterpretersOffice\Admin\ServiceTestCommand::class,
        ],
    ],   
];

```

because that’s what the instructions seemed to say, although “dependencies” sounds more like Mezzio than MVC.

---

<div class="post-metadata">

**Author:** ![george](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/george/32/676_2.png) [@george](https://discourse.laminas.dev/u/george)\
**Post date:** [June 17, 2020, 10:33pm UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673/7 "2020-06-17T22:33:50Z")

</div>

> [@davidmintz](#):
>
> although “dependencies” sounds more like Mezzio than MVC.

Yes, sorry, I don’t really use MVC anymore - I was here [writing this RFC](https://discourse.laminas.dev/t/rfc-laminas-cli-auto-add-invokable-factory-for-commands/1675) when I saw your post and thought “Aha, maybe that’s it!”

---

<div class="post-metadata">

**Author:** ![matthew](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/matthew/32/14_2.png) [@matthew](https://discourse.laminas.dev/u/matthew)\
**Post date:** [June 29, 2020, 2:46pm UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673/8 "2020-06-29T14:46:29Z")

</div>

I see two things:

- Use the `service_manager` key instead of the `dependencies` key in your configuration. `dependencies` is used by Mezzio, while the MVC uses `service_manager` (the reason is because Mezzio allows any PSR-11 container, while the MVC currently only allows laminas-servicemanager).

- `configure()` and `execute` both need to be declared as `protected`, IIRC.

---

<div class="post-metadata">

**Author:** ![davidmintz](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/davidmintz/32/213_2.png) [@davidmintz](https://discourse.laminas.dev/u/davidmintz)\
**Post date:** [June 29, 2020, 4:51pm UTC](https://discourse.laminas.dev/t/trouble-getting-started-with-laminas-cli-and-mvc-app/1673/9 "2020-06-29T16:51:49Z")

</div>

Thanks! I bet that will do the trick. I’ve since moved on and just solved what I was dealing with by other, more crude methods, even discarded some of the code I was playing with. Soon as I get a chance I will give it another go. Maybe even come up with a PR to add this point to the documentation 🙂
