Static pages#9
Conversation
| </li> | ||
| <li class="nav-item"> | ||
| <a class="nav-link px-3 fw-semibold fs-5 transition-all" href="{{ url('page::dotkernel-packages-oss-lifecycle') }}">Packages Lifecycle</a> | ||
| <a class="nav-link px-3 fw-semibold fs-5 transition-all" href="{{ url('page::static-page', {'static-page': 'dotkernel-packages-oss-lifecycle'}) }}">Packages Lifecycle</a> |
There was a problem hiding this comment.
Why couldn't you reuse the already existing static page implementation for this?
If you look in config/autoload/local.php.dist you'll find an array where static page routes are defined (under routes → page).
There was a problem hiding this comment.
I created new route because i wanted to use some data from database (recent posts or categories) and I didn't figured out how to send my data using routes from local.php for every static page(contact, about...)
There was a problem hiding this comment.
Your surrent solution does not differ from the original one - it just moves the logic to a different place.
Injecting those dependencies should work the same way in both cases:
Your solution
Injects TemplateRendererInterface, PostRepository and CategoryRepository into src/Blog/src/Handler/GetStaticPageDataHandler.php via src/Blog/src/Factory/StaticPages/GetStaticPageDataFactory.php.
Original solution
Injects TemplateRendererInterface into src/Page/src/Handler/GetPageViewHandler.php via src/Page/src/Factory/GetPageViewHandlerFactory.php.
You should be able to reuse this factory to inject whatever you need into GetPageViewHandler via GetPageViewHandlerFactory.
After that, you can remove GetStaticPageDataHandler and GetStaticPageDataFactory.
| </ul> | ||
| <div class="d-none d-lg-block"> | ||
| <a href="{{ url('page::contact') }}" class="btn btn-primary rounded-pill px-4">Contact</a> | ||
| <a href="{{ url('page::static-page', {'static-page': 'contact'}) }}" class="btn btn-primary rounded-pill px-4">Contact</a> |
| </div> | ||
| </div> | ||
| </div> | ||
| {% if posts is defined and posts %} |
There was a problem hiding this comment.
| {% if posts is defined and posts %} | |
| {% if posts is defined and posts is iterable %} |
| 'posts' => $posts, | ||
| ]); | ||
| } catch (Throwable $e) { | ||
| return $this->notFound(); |
There was a problem hiding this comment.
The notFound() method duplicates the database query behind this code:
$categories = $this->categoryRepository->getCategories();Since the functionality of the notFound() method is not reused elsewhere, you could replace this live with its contents - solving this way for the code duplication.
| $this->template->render('error::404', [ | ||
| 'categories' => $categories, | ||
| ]), | ||
| 404 |
There was a problem hiding this comment.
See if you have vendor/fig/http-message-util/src/StatusCodeInterface.php; if it does not exist, skip the below.
You should avoid using numeric status codes and use the constants defined as standards.
They have the same effect, we just prefer to use standards when possible. It also helps readability when you see StatusCodeInterface::STATUS_NOT_FOUND instead of 404.
There was a problem hiding this comment.
I will fix this
| $app->get('/author/{slug}/', [GetAuthorResourceHandler::class], 'page::author-resource'); | ||
| $app->get('/{categorySlug}/{slug}/', [GetPostResourceHandler::class], 'page::blog-resource'); | ||
|
|
||
| $app->get('/{static-page}/', [GetStaticPageDataHandler::class], 'page::static-page'); |
There was a problem hiding this comment.
Related to my comments regarding the existing static pages implementation.
Static pages and generic route