DEV Community

Cover image for Getting started with Slim PHP framework by building a very simple MVC/OOP app

Getting started with Slim PHP framework by building a very simple MVC/OOP app

charliedeveloper on June 29, 2018

Aim: We are going to build a Slim application that creates a farm pen and outputs the noises that the cow & chicken inside the pen make. Requ...
Collapse
 
bvrulez profile image
bomben

I have the error message "Entry \"Farm\\Controllers\\PenController\" cannot be resolved: Parameter $container of __construct() has no value defined or guessable\nFull definition:\nObject (\n class = Farm\\Controllers\\PenController\n lazy = false\n __construct(\n $container = #UNDEFINED#\n )\n)" and think it might be due to this: "In contrast with Slim 2 and Slim 3, Slim 4 does not ship with a DI container, but instead, supports any PSR-11 compatibly DI container that you provide." (akrabat.com/dependency-injection-i...)

But since I am a total noob it could also be another problem. :)

Collapse
 
bvrulez profile image
bomben

The problem was, that the parameter that gets passed to the constructor is tested for its type by slim. So we have to type-hint it now with "Container". But this is just one of the problems this tutorial raises when applied to Slim 4.

Collapse
 
bvrulez profile image
bomben • Edited

I like this tutorial very much for getting a basic grasp on what is going on. But there is no src/dependencies.php (also no dependAncies.php). Is this due to a new version of slim? How can we proceed anyway? Thanks a lot!

EDIT: I tried it anyway (creating a depandencies.php and putting in that single line) and got the following error that I do not understand since this file exists: Uncaught Error: Class 'App\Application\Handlers\HttpErrorHandler

Collapse
 
lucasxsl profile image
lucas-xsl

packagist.org/packages/slim/slim-s...

According to the time the article was published, this version has this file;

this commend:
composer create-project slim/slim-skeleton slimFarm 3.1.5

Collapse
 
d4rkfrancis profile image
d4rkfr4ncis

Getting the following error:

{
"statusCode": 500,
"error": {
"type": "SERVER_ERROR",
"description": "Call to undefined method Farm\Factories\PenModelFactory::getCowNoise()"
}
}

Collapse
 
charliedevelops profile image
charliedeveloper

Thanks! Really pleased you liked it!

Collapse
 
zamfir80 profile image
Razvan Zamfir

Great article! You're a great PHP developer aren't you? Will you give me a hand with improving this Slim 3 API? Thanks!