Zendframework Routing Issue

327 Views Asked by At

I have been setting my routes in my application.ini file which works for all the ones i have setup. The problem is when there are multiple actions within that controller and i try to use the routes in other actions.

For instance i have created the following in my application.ini for paging and column sorting

resources.router.routes.search.route = "search/:page/:col/:sort/:limit/"
resources.router.routes.search.defaults.controller = search
resources.router.routes.search.defaults.page = 1
resources.router.routes.search.defaults.col = time
resources.router.routes.search.defaults.sort = default
resources.router.routes.search.defaults.limit = 50
resources.router.routes.search.reqs.page = \d+
resources.router.routes.search.reqs.col = \w+
resources.router.routes.search.reqs.sort = \w+
resources.router.routes.search.reqs.limit = \d+

The above works when I'm on the default action of that page like

www.mywebsite.com/search/2/

Would bring up the second page of the results. But if I try the same on another action,

www.mywebsite.com/search/action/2

It just shows a blank page. I tried creating its own settings in the ini and that did not work. I've run across this problem before but usually just gave up and separated things into different controllers but i would rather have different actions.

Any help would be much appreciated.

Matt

1

There are 1 best solutions below

3
On

search/:page/:col/:sort/:limit/ doesn't match www.mywebsite.com/search/action/2. Your route is looking for search/ followed by a digit (\d) that represents the page number; however, you're requesting search/ followed by the string action. I would suggest adding another parameter to your route: search/:action/:page/:col/:sort/:limit, defaulting action to index.

Requesting the first page of the default action stays the same (search). Requesting page 2 of the default route will now be search/index/2/, but you can now specify a different action (search/action/2).