Kohana Route setup for different actions - kohana

I have route like this (Kohana 3.3)
Route::set('project', 'project(/<action>(/<id>(/<idfile>)))')
now is possible querys like this
localhost/kohana/project/edit/16
localhost/kohana/project/list/
I want to use pagination on action list - so i need to change "id" to "page" in my route only on this action
Do I should use Regulars or theres a stock approach ?

Solved by next Route
Route::set('project', 'project(/<action>(/page/<page>)(/<id>(/<idfile>)))')

Related

Are this two routes same in nodejs?

Routes in Express:
/search/:company-name
/search/:category-name
I can see that first one is fired for both requests so they are same, but is there a way to solve this without involving for example:
/search/company/:company-name
/search/category/:category-name
Yes, they are the same.
The router just see a route that starts with search/ and ends with a wildcard. The only thing that change is the name you give to that wildcard, which doesn't matter for the router, it's still the same URL.
You can solve this by either changing the route, or you can parse the route argument (the wildcard) and do something different depending on its value.
You could use a query instead of a param.
Your urls would be:
/search?company=company-name
/search?category=category-name
Your route is /search and you use req.query instead of req.params.
It's either that,
or your solution of changing the route,
or somehow parsing the parameter to decide whether it's a company or a category
or changing your route to a post and using key-value pairs in the post body

How do I create an action for a model with specific :id?

So, I am using sails.js framework and I want to create an action "invite" for a user with id "5". Where should I place a function "invite"? I want to achieve a URL similar to this: "http://example.com/api/users/5/invite". Blueprints are ON.
In routes.js add something like
'post /api/users/:id/invite': 'UserController.invite'
and then add your invite function in the UserController. The id param from the route will be available in req.param('id')

Zend Framework 2 Paginating Search Results

I'm making a complex search form with a lot of inputs to query and I want to paginate the search results using Zend Framework 2.
I've found a few people who are trying to do something similar but I have yet to find a good solution.
Some people suggested switching to $_GET method instead of $_POST but i would prefer to avoid this because of the number of form elements.
The results are coming up fine, but as soon as i try to navigate to the second page, the query is lost and it is essentially paginating all records on the table.
What is the best way to store the original search query so that the paginated results are the actual results?
I can't imagine ZF2 doesn't have an easy way to paginate $_POST results but I haven't been able to figure it out yet
well you either need to repost the search parameters on every page request or keep the search parameters in a session and on the second request check if the request is get or post and use the session if it is get

Expression Engine - passing multiple categories as URL segments

I'm trying to create a product filter with deep-linking capability. Essentially, I want the user to be able to filter my product list on multiple categories and have the URL reflect the filtering they've done.
So it would start as:
www.site.com/products/
My first level of category filtering already works. So I can use EE's regular handling of URL segments to get to my first level of filtering. For instance:
www.site.com/products/leatherthongs
Returns a filtered subset showing only a spectacular collection of leather thongs. But now I want the user to be able to filter on another category - color for instance. This is where stuff stops working.
EE's way of handling multiple categories inside templates (with ampersands or pipes) doesn't work in the URL:
www.site.com/products/leatherthongs&red
Nor does any variation that I've tried.
My next move is to create a simple raw PHP method that can capture regular querystring parameters and then inject them into the {entries} tag before rendering. Not very difficult, but quite ugly. I would love to know if there is a way to handle multiple categories in the URL natively.
Thanks for your time.
Have you considered using Low's Seg2Cat add-on? I'm not sure how complex you want to make this but it seems that you could specify something in your channel:entries loop like categories='{segment_2){if segment_3}|{segment_3_category_id}{/if}'
This exact syntax is untested but I have had success in the past with a similar solution.

how do I implement a kohana pagination in MVC?

that's it. How do I implement the Kohana pagination library in MVC way? which code should go to the model? to the controller? to the view? I have seen tons of examples but none of them are implemented in MVC.
Pagination has two parts: the records filter part which should go in the controller and the display part which goes into the view. The example in the pagination library help is correct.
If you want to implement your own pagination library take a look here.
To fulfill the MVC philosophy, you could:
1) have 2 methods in a model which make the same query but one returns only the row count and the other returns the actual result, being able to apply a LIMIT and an OFFSET.
Let's say, Some_Model::get_results() and Some_Model::get_result_count()
2) In your controller, when pagination is needed, you call Some_Model::get_result_count() to know the total quantity of rows, and pass that value to Kohana's pagination initialization, to get the pages links, which you put into a variable to pass to the view.
3) In the view, you echo the variable that has the pages links, and voila!
Of course this assumes you read the Kohana documentation for pagination and its examples.
Hope it helps.

Resources