routing

Different routes but using the same controller for model subclasses in Rails

爷,独闯天下 提交于 2019-12-08 06:40:54
问题 I have a Model Property which has subclasses using STI, and which I would like all to use the same controller with only different view partials depending on the subclass. Property Restaurant < Property Landmark < Property It works find except I'm not sure how to discern the subclass inside the controller to render the correct view. Ie. /restaurants works and goes to the properties controller but I can't tell that they want the Restaurant subclass? map.resources :restaurant, :controller =>

What's wrong with this Symfony2 route?

萝らか妹 提交于 2019-12-08 06:01:28
问题 I've set up a route using annotations. Looks right to me, Symfony2 says it's wrong. Here's the route: @Route("/news/{id}/{slug}", name="newsarticle") Here's a sample URL which I think matches the route: http://somesite.com/news/202/my-news-title Here is the function skeleton: public function newsArticleAction($id, $slug) { } What am I missing here? I get a 500 error and the log says: [2012-10-30 20:36:35] request.INFO: Matched route "newsarticle" (parameters: "_controller": "App\SiteBundle

How to do URL matching regex for routing framework?

倾然丶 夕夏残阳落幕 提交于 2019-12-08 05:59:15
问题 I already have a routing method that matches this pattern: /hello/:name that set name to be a dynamic path, I want to know how to make it: /hello/{name} with the same regex. How to add optional trailing slash to it, like this? /hello/:name(/) or /hello/{name}(/) This is the regex I use for /hello/:name @^/hello/([a-zA-Z0-9\-\_]+)$@D The regex is auto generated from PHP class private function getRegex($pattern){ $patternAsRegex = "@^" . preg_replace('/\\\:[a-zA-Z0-9\_\-]+/', '([a-zA-Z0-9\-\_]+

Expression Language in conditional routing - service in context

时间秒杀一切 提交于 2019-12-08 05:36:07
问题 According to docs, there are only two things available by default, while using expression language in conditional routes - context and request . I would like to use foo service with boolean bar() method to determine condition. How to inject foo service into this condition? So far I've tried: some_route: path: /xyz defaults: {_controller: "SomeController"} condition: "service('foo').bar()" and some_route: path: /xyz defaults: {_controller: "SomeController"} condition: "service('foo').bar() ===

Ionic 3 - add a 404 page to URL Router

帅比萌擦擦* 提交于 2019-12-08 05:26:53
问题 In this Question I found a answer for 404 pages in Ionic 3 Routing: Custom 404 page Ionic 3 But I have a problem in my router when I use parameters. If I add this to my router: { component: EventdetailsPage, name: 'Details', segment: 'event/:eventId',defaultHistory: [HomePage] }, With this line at the bottom of my config, every call to a page with parameters will redirected: { component: NotFoundPage, name: "*", segment: ":**", defaultHistory: [NotFoundPage] }, on every call of .../event/123

How to use Yii2 Sluggable Behavior?

巧了我就是萌 提交于 2019-12-08 05:24:54
问题 I have defined this behavior as per documentation instructions. public function behaviors() { return [ TimestampBehavior::className(), [ 'class' => SluggableBehavior::className(), 'attribute' => 'title', ], ]; } In my config url manager I have defined custom rule like this: example.com/article/1 'urlManager' => [ 'class' => 'yii\web\UrlManager', 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ 'article/<id:\d+>/<slug>' => 'article/view', ], ], My view action is: public

Named routes in param pre-conditions

回眸只為那壹抹淺笑 提交于 2019-12-08 04:58:46
问题 I'd like to use a Route Param Pre-Condition to fetch portfolio items by "slug" if the :slug parameter is set in the URL. I also, however, would like to use a RegExp to match the URI. Are named captures supported in node? Can I give that ([-\w]+) capture a name so the slug pre-condition gets fired? app.param('slug', function(req, res, next, slug){ // get thing from database by slug }) //app.get('/work/view/:slug', function(req, res){ app.get(/^\/work\/view\/([-\w]+)/, function(req, res){ //

ASP.NET MVC 2 actions for the same route?

烂漫一生 提交于 2019-12-08 04:54:55
问题 Suppose I have defined route like that, context.MapRoute( "Preview", "/preview/{id}/{type}", new { controller = "Preview", action = "Invoice", id = UrlParameter.Optional, type = UrlParameter.Optional } ); I have controller with action Invoice public ActionResult(int id, string type) { if (type == "someType") { // ... } else { // .. } } I want to get rid of If-Else case inside the action. Is it possible to attribute action somehow, so ASP.MVC would distinguish between both, like: Just a

Rails nested resource issue

狂风中的少年 提交于 2019-12-08 04:05:21
问题 I have a couple of resources, a grant_application, and a household which are related with a has_one class GrantApplication < ActiveRecord::Base has_one :household, :dependent => :destroy end class Household < ActiveRecord::Base belongs_to :grant_application end ..and I also use the following route.. map.resources :grant_applications do |grant| grant.resource :household end However, I am having real problems when trying to create the form for /grant_applications/1/household/new Using <% form

How to use optional parameters at zend routing

寵の児 提交于 2019-12-08 03:56:39
问题 I want to set a similar routing to the standard-router with optional parameters, e.g.: intranet.route = 'intranet/:controller/:action/:title/:id' only the id-parameter doesn't need a value. i tried giving it an default value like null - but then the variable is still set, but i don't want it to exist at all when the user does not give it any value also, how can i set up a route with dynamic values, just like this: intranet/index/index/Front%20Page/123/foo/bar then the variable $foo exists