Answer the question
In order to leave comments, you need to log in
What about the controller?
Hello! When following a link from the main page to a page from a particular category, I use CategoryController which is a child (by routes) of the Shop module, here is the configuration file where it is described:
'router' => [
'routes' => [
'shop' => [
'type' => Literal::class,
'options' => [
// Change this to something specific to your module
'route' => '/shop/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
'category' => [
'type' => Segment::class,
'options' => [
'route' => 'category/[:action/][:id/]',
'constraints' => [
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
],
'defaults' => [
'controller' => Controller\CategoryController::class,
'action' => 'index',
]
]
],
// You can place additional routes that match under the
// route defined above here.
],
],
],
],
zblog.local/shop/category/1
zblog.local/shop/category/?page=2, but the id must remain since the controller's work is tied to it. The code that displays the paginator on the page:
<?= $this->paginationControl($products,
'Sliding',
'application/partial/paginator',
['route' => 'shop/category']); ?>
Answer the question
In order to leave comments, you need to log in
Means so - write such route.
And about the paginator, I wrote to you further.
'router' => [
'routes' => [
/** Configuration of the 'shop' routes. */
'shop' => [
'type' => 'Literal',
'options' => [
'route' => '/shop/',
'defaults' => [
'controller' => Controller\IndexController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
/** Configuration of the 'shop/category' routes. */
'category' => [
'type' => 'Literal',
'options' => [
'route' => 'category/',
'defaults' => [
'controller' => Controller\CategoryController::class,
'action' => 'index',
],
],
'may_terminate' => true,
'child_routes' => [
/** Configuration of the 'shop/category/action' routes. */
'action' => [
'type' => 'Segment',
'options' => [
'route' => '[:action]',
'constraints' => [
'action' => '(create)',
],
],
],
/** Configuration of the 'shop/category/category' routes. */
'category' => [
'type' => 'Segment',
'options' => [
'route' => '[:id/]',
'constraints' => [
'id' => '[0-9]+',
],
'defaults' => [
'id' => null,
],
],
'may_terminate' => true,
'child_routes' => [
/** Configuration of the 'shop/category/category/action' routes. */
'action' => [
'type' => 'Segment',
'options' => [
'route' => '[:action]',
'constraints' => [
'action' => '(update|delete)',
],
],
],
],
],
],
],
],
],
],
],
Am I the only one who sees the routes in this framework as miserable?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question