What you need to know:
PHP and Composer.
The HTTP message interfaces specify a way of interaction with HTTP. It is an alternative to using HTTP wrapper ($_GET, $_POST, etc.).
Slim is a PSR-7 compliant micro framework for PHP. To use Slim with PSR-7 we need to install PSR-7 binding.
At its core, Slim is a dispatcher that receives an HTTP request, invokes an appropriate callback routine, and returns an HTTP response. That's it.
What are your expectations of a mature PHP web application?
Create and explore a Slim framework skeleton project.
php .\composer.phar create-project slim/slim-skeleton slim-framework-skeleton
Problem 1
- Root composer.json requires phpunit/phpunit ^9.5.26 -> satisfiable by phpunit/phpunit[9.5.26, ..., 9.6.22].
- phpunit/phpunit[9.5.26, ..., 9.6.22] require ext-mbstring * -> it is missing from your system. Install or enable PHP's mbstring extension.
Enable "mbstring" extension in "php.ini" file.
GitLab: ./practical-02/
As the skeleton slim application is too big, we create a new application from scratch. There is a useful Get Started guide. Here are the steps to follow:
composer require slim/slim:"4.*"
composer require slim/psr7
php -S 127.0.0.1:8090
Rest of the assignment is structured as a "step-by-step" guide to implement the final functionality. I would recommend you to follow it, especially if you are not sure what to do.
Add error handling using middleware.
Add following pages into your application at given URLs:
The home page should contain some information about the application. The exact content is not important, it just must not be empty!
For all the others you can now return just a random string to make sure it works.
At the "register an author"" page your can fill in a form. The form must contain a name input as a text. User can submit the form using "Register" button.
The form must be submitted at the "register an author" page using POST. As a response to a POST return HTML with message "{name}, welcome!". Where "{name}" is the value user provided. You can get "name" from the request POST parameters.
The "authors list"" page should return HTTP code 501. The HTML should contain a message "Coming soon!".
Both article related sites, "articles list" and "create an article" should return HTTP code 501. The HTML should contain a message "Coming soon!".
Put all the HTML content into templates files. The template files should be located in "./template/" directory. Create one template file per view. Use PHP renderer to render the templates.
Create a layout for your application. The layout must include a navigation header with links to the all pages. In addition, it must include footer with a following copyright notice.
© 2024-2025 NSWI153
Add PHP-DI and Slim bridge to your application.
Create a controller for each page and use Controllers as services.
Put controller classes into the "./src" directory. You may split more functionality into "./app" or "./application" directory as we have seen in Slim skeleton project.
Inject the PHP renderer to controllers using a constructor.
Deploy your application to webik.ms.mff.cuni.cz/{your-user-name}/nswi153/practical-02.
...