Skip to content

Commit

Permalink
[skip ci][doc] add parameter typing in router
Browse files Browse the repository at this point in the history
  • Loading branch information
jcheron committed Jan 10, 2022
1 parent bb86b9c commit dae0f64
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions docs/controller/router.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Routes can also be associated more conventionally with an action of a controller
The method ``FooController::index()`` will be accessible via the url ``/bar``.

In this case, the **FooController** must be a class inheriting from **Ubiquity\controllers\Controller** or one of its subclasses,
In this case, the **FooController** must be a class inheriting from **Ubiquity\\controllers\\Controller** or one of its subclasses,
and must have an **index** method:

.. code-block:: php
Expand Down Expand Up @@ -292,6 +292,62 @@ but not with that one:
- ``products/all/test``


Parameter typing
^^^^^^^^^^^^^^^^
The route declaration takes into account the data types passed to the action, which avoids adding requirements for simple types (int, bool, float).

.. tabs::

.. tab:: Attributes

.. code-block:: php
:linenos:
:caption: app/controllers/ProductsController.php
:emphasize-lines: 7
namespace controllers;
use Ubiquity\attributes\items\router\Route;
class ProductsController extends ControllerBase{
...
#[Route('products/{productNumber}')]
public function one(int $productNumber){
// ...
}
}
.. tab:: Annotations

.. code-block:: php
:linenos:
:caption: app/controllers/ProductsController.php
:emphasize-lines: 6
namespace controllers;
class ProductsController extends ControllerBase{
...
/**
* @route("products/{productNumber}")
*/
public function one(int $productNumber){
// ...
}
}
The defined route matches these urls:
- ``products/1``
- ``products/20``
but not with that one:
- ``products/test``


Correct values by data type:
- ``int``: ``1``...
- ``bool``: ``0`` or ``1``
- ``float``: ``1`` ``1.0`` ...

Route http methods
^^^^^^^^^^^^^^^^^^

Expand Down Expand Up @@ -678,7 +734,7 @@ These parameters can be retrieved through a public data member:
.. code-block:: php
:linenos:
:caption: app/controllers/FooController.php
:emphasize-lines: 3
:emphasize-lines: 4
namespace controllers;
Expand Down

0 comments on commit dae0f64

Please sign in to comment.