Skip to content

Instantly share code, notes, and snippets.

@odan
Last active January 15, 2022 11:22
Show Gist options
  • Star 15 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save odan/c8bee474b0054a06776481a6c8de1d8f to your computer and use it in GitHub Desktop.
Save odan/c8bee474b0054a06776481a6c8de1d8f to your computer and use it in GitHub Desktop.
Slim 4 Tutorial
@blacktornado
Copy link

blacktornado commented Oct 6, 2020

yes @odan i understand your point as it is looking for the public directory which has index.php, as i am using php internal web server.

coming to another scenario where i have web server that points to htdocs and my slim is inside htdocs/somefolder/slim i am hitting the url with 10.xxx.xxx.x:port/somefolder/slim the request lands successfully to public/index.php from there it goes to bootstrap.php to container.php and finally lands to routes.php where if i do a var_dump($app) it gives me resultset but i am getting 404 error with

Type: Slim\Exception\HttpNotFoundException
code: 404
Message: Not Found
File: /www/zendphp7/htdocs/somefolder/slim/vendor/slim/slim/Middleware/RoutingMiddleware.php

to make it work if i remove this line return function(App $app){ from router.php and again add this two lines in router.php
$app = AppFactory::create();
$app->setBasePath('/somefolder/slim');
its working.

@odan
Copy link
Author

odan commented Oct 6, 2020

@blacktornado I think it makes no sense to create a new $app instance, because per request there should be only one Slim instance.
If you have further technical questions, please create an issue here: https://github.com/odan/slim4-tutorial/issues

@marcusball
Copy link

marcusball commented May 29, 2021

This is a great tutorial, thank you so much!

Is there any particular reason to separate the Read and Create into separate repositories and services? In this example, would it be against design patterns to use a single UserRepository containing both insertUser and getUserById methods? Similarly, is it suggested to not combine the Service methods into a single UserService?

@odan
Copy link
Author

odan commented May 29, 2021

Hi @marcusball Please note that this is not an Active-Record (anti-) pattern. The shown pattern follows Command–query separation (CQS) on routing level. So read and write access is separated. To respect the SOLID (see SRP) principles, the service class is responsible only for one specific task (use case) and not more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment