Hi, I'm back again with some more code samples regarding the routes that I want to achieve,
I left the routes at the end of the project so I could focus more important things. Now I'm struggling to get pagination working properly.
here are some routes:
This works fine, the only problem is that if there's no page number in url (/mac/browsers/) the default page is 3.
// route for category with pagination
$this->add('/(windows|mac|mobile)/([a-zA-Z0-9\-]+)/?[0-9+]?/?',
array(
'module' => 'category',
'namespace' => 'Category\controllers',
'controller' => 'Category',
'action' => 'index',
'os' => 1,
'category' => 2,
'page' => 3
)
);
This also works fine, and fixes the problem with the above one, but it's conflicting with subcategory routes.
$this->add('/(windows|mac|mobile)/([a-zA-Z0-9\-]+)/?{page}?/?',
array(
'module' => 'category',
'namespace' => 'Category\controllers',
'controller' => 'Category',
'action' => 'index',
'os' => 1,
'category' => 2,
'page' => 3
)
)->convert('page', function($page) {
if (!is_int($page))
return 1;
else
return $page;
});
This route is working ok if the category route is using [0-9+] regex to get the page param,
or page number is present in URL.
// subcategory with pagination - default tab
$this->add('/(windows|mac|mobile)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?{page}?/?',
array(
'module' => 'subcategory',
'namespace' => 'Subcategory\controllers',
'controller' => 'Subcategory',
'os' => 1,
'subcategory' => 3,
'category' => 2,
'action' => 'index',
'page' => 4
)
)->convert('page', function($page) {
if (!is_int($page)) return 1;
});
The problem that I have is that if I use {page} instead of regex [0-9+] in category route, the app follows the category route and sets page = 1,
so I'm not able to use that, therefore getting into the other issue caused by default value of page param which is the param index number from the URL,
in my case 3.
I think this could be avoided if the parser would return null instead of param index.
I hope this makes sense :)