Recommended PHP version for tuturial: Getting Started with Laminas MVC Applications

I was follow the tutorial Getting Started with Laminas MVC Applications (Overview - tutorials - Laminas Docs) and got stuck on:

—%<-----------------------------------------------------------------------------

An error occurred

An error occurred during execution; please try again later.

Additional information:

ArgumentCountError

File:

…/laminas-mvc-tutorial/module/Album/src/Controller/AlbumController.php:16

Message:

Too few arguments to function Album\Controller\AlbumController::__construct(), 0 passed in …/laminas-mvc-tutorial/vendor/laminas/laminas-servicemanager/src/ServiceManager.php on line 664 and exactly 1 expected
—%<-----------------------------------------------------------------------------

PHP version:

PHP 7.4.11 (cli) (built: Oct 6 2020 10:34:39) ( NTS )
Copyright © The PHP Group
Zend Engine v3.4.0, Copyright © Zend Technologies
with Zend OPcache v7.4.11, Copyright ©, by Zend Technologies
with Xdebug v2.9.6, Copyright © 2002-2020, by Derick Rethans

composer.lock reads


“require”: {
“nikic/php-parser”: “^4.0”,
“php”: “^7.2 || ^8.0”
},

Please, can anybody confirm this tutorial works with PHP 7.4.x? :bomb:

Thanks in advance.

Hello and welcome to our forums! :smiley:

Yes, it works, but the error message you get has nothing to do with the version of PHP.

The error message is clear: the controller class expects at least one parameter. I guess you are missing one more step of the instructions.

Please compare the code examples of “Database and models – Back to the controller”. There is one parameter added to the controller and in the next step a factory is created.

If you still have problems, please tell us where you got the problem in the tutorial. Thanks!

@froschdesign, Thanks for the quick answer!

I’ve restarted the tutorial three times, step by step, and I’m still stuck on 2 different errors on my branches …

(1) Too few arguments to function Album\Controller\AlbumController::__construct(), 0 passed in …/laminas-mvc-tutorial/vendor/laminas/laminas-servicemanager/src/ServiceManager.php on line 664 and exactly 1 expected

(2) Service with name “Album\Model\AlbumTable” could not be created. Reason: Could not resolve value for parameter “tableGateway” of type Laminas\Db\TableGateway\TableGatewayInterface in class Album\Model\AlbumTable (requested as Album\Model\AlbumTable)

Is there any way to get the files representing the final state of this tutorial to be able to diff them with mine and spot what’s is wrong ?

Maybe would be a good idea to provide a “download tutorial files” link at Conclusion section (Conclusion - tutorials - Laminas Docs) with the resulting file-tree of this tutorial …

Thanks.

It almost sounds like you forgot to remove Controller\AlbumController::class => InvokableFactory::class, from module.config.php as instructed right above Listing Albums