Skip to content

Commit 548ebb5

Browse files
authored
Merge pull request #10 from dotkernel/documentation_update
Documentation update
2 parents 048aba0 + dd59d8b commit 548ebb5

5 files changed

Lines changed: 60 additions & 18 deletions

File tree

docs/book/v1/how-tos/create-pages.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
# Creating pages
22

3-
## The `action` function
3+
## Register the page route
44

5-
The first step is to add the new pages in `src/Page/src/Controller/PageController.php`.
6-
This means adding an `Action` function for each page, as seen below.
5+
Open `config/autoload/local.php` and locate the **routes** key.
6+
Under the **page** key you will find an associative array with a couple of already existing routes.
7+
You create a new route by appending a new line to that array:
78

89
```php
9-
public function examplePageAction(): ResponseInterface
10-
{
11-
return new HtmlResponse(
12-
$this->template->render('page::example-template')
13-
);
14-
}
10+
'example-page' => 'example-template',
11+
```
12+
13+
> The array key is the page slug, the array value is the template name used by that page.
14+
15+
In order to be displayed this new `example-template` needs to be added to the website's navigation area.
16+
To do this, open `src/App/templates/layout/default.html.twig`, locate the `ul` inside the `div` with id `navbarHeader` and append the below code to it:
17+
18+
```twig
19+
<li class="nav-item">
20+
<a class="nav-link" href="{{ url('page::example-template') }}">Example</a>
21+
</li>
1522
```
1623

1724
## The page content
@@ -77,6 +84,3 @@ public function getTemplates(): array
7784
## Accessing the page
7885

7986
The url for the new page in this example is `/page/example-page`.
80-
81-
> Because of the way routing works, dot (.), dash (-), underscore (_) are filtered from the `action` parameter in the routing `/page[/{action}]`.
82-
> As a result, the `examplePageAction` function in called.

docs/book/v1/how-tos/routing.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Routing
2+
3+
In our current implementation we are using request handlers instead of controllers in order for DotKernel to comply with the PSR-15 standard.
4+
5+
## How are we implementing handlers?
6+
7+
### Declaration of the routes and modules
8+
9+
Currently, our structure uses modules, routes and template names.
10+
Those are being declared in the file `config/autoload/local.php` in the following way:
11+
12+
```php
13+
'routes' => [
14+
'page' => [
15+
'about' => 'about',
16+
'who-we-are' => 'who-we-are',
17+
],
18+
],
19+
```
20+
21+
In this case `page` represents the module and `'about' => 'about'` represents the page slug and its assigned `.twig` template.
22+
To clarify, this creates a route called `page.about` in the `page` module, it loads the template file `src/Page/templates/page/about.html.twig` and can be accessed at `/page/about`.
23+
With each request, when matching one of these routes, the `PageHandler` will detect the current route name and render the matching template.
24+
25+
### Manipulating the declared routes and modules
26+
27+
Each module has a `RoutesDelegator.php` file (ex. `src/Page/src/RoutesDelegator.php`).
28+
In this file we are retrieving the application config from the container and we loop over each module and their assigned routes.
29+
30+
```php
31+
$routes = $container->get('config')['routes'] ?? [];
32+
foreach ($routes as $moduleName => $moduleRoutes) {
33+
foreach ($moduleRoutes as $routeUri => $templateName) {
34+
$app->get(
35+
sprintf('/%s/%s', $moduleName, $routeUri),
36+
[PageHandler::class],
37+
sprintf('%s::%s', $moduleName, $templateName)
38+
);
39+
}
40+
}
41+
```

docs/book/v1/installation/configuration-files.md

Lines changed: 0 additions & 3 deletions
This file was deleted.

docs/book/v1/introduction.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Dotkernel light
22

3-
Dotkernel Light is an application (skeleton) using Mezzio microframework and Laminas components.
3+
Dotkernel Light is a PSR-15 compliant application (skeleton) using Mezzio microframework and Laminas components.
44
It's designed as a minimal project to generate a simple website, like a presentation site.
55

66
Read on to find out more about the application:
@@ -12,7 +12,7 @@ Read on to find out more about the application:
1212
> Check out our [demo](https://light.dotkernel.net/).
1313
1414
![OSS Lifecycle](https://img.shields.io/osslifecycle/dotkernel/light)
15-
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/light/1.0.0)
15+
![PHP from Packagist (specify version)](https://img.shields.io/packagist/php-v/dotkernel/light/1.1.0)
1616

1717
[![GitHub issues](https://img.shields.io/github/issues/dotkernel/light)](https://github.com/dotkernel/light/issues)
1818
[![GitHub forks](https://img.shields.io/github/forks/dotkernel/light)](https://github.com/dotkernel/light/network)

mkdocs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ nav:
1616
- Installation:
1717
- "Getting Started": v1/installation/getting-started.md
1818
- "Composer": v1/installation/composer.md
19-
- "Configuration Files": v1/installation/configuration-files.md
2019
- "Development Mode": v1/installation/development-mode.md
2120
- "Running the Application": v1/installation/running-the-application.md
2221
- "FAQ": v1/installation/faq.md
2322
- How to:
2423
- "Use NPM Commands": v1/how-tos/npm-commands.md
24+
- "Routing": v1/how-tos/routing.md
2525
- "Create Pages": v1/how-tos/create-pages.md
2626
- "Set Up Twitter and OpenGraph Cards": v1/how-tos/twitter-opengraph-cards.md
2727
- "Edit the Top Menu": v1/how-tos/edit-top-menu.md

0 commit comments

Comments
 (0)