I want to clear everything from my url and just leave www.mydomain.com/... no profiles no controller no action no ids no vars in the url...
is that posible?
Router::connect('/', array('controller' => 'something', 'action' => 'here', 123, 'some' => 'named_params'));
nothing wrong with doing that. its not a hack, and its 100% reliable. and no, you dont need to do it with htaccess
Related
A plea for your indulgence. I have searched for answers and tried many things, so I now humbly turn here for help. It should be simple: I'm moving to CakePhp and I want to redirect my old query strings (action=show&id=2) to groovy cake URLs (/Feature/view/2).
I've tried this in the .htaccess file in the webroot:
RewriteCond %{QUERY_STRING} ^action=show&id=([0-9]+)$
RewriteRule /Features/view/%1? [R,L]
No love. I also tried:
RewriteRule action=show&id=([0-9]+) /Features/view/$1 [L]
No love.
I tried Cakephp's routes.php with:
Router::connect('index.php?action=show&id=([0-9]+)',array('controller' => 'features', 'action' => 'view', 'id' => $1));
But I've seen no evidence that regex can be used that way in routes.php so that was really just throwing up a prayer.
It's possible to do this. Right? Thanks for any advice!
I think you can do it within router.php!
Maybe, you can get away with:
Router::connect('?action=:action&id=:id',
array(
'controller' => 'myController',
'action' => 'myAction',
),
array(
'action' => '[a-zA-Z]+',
'id' => '[0-9]+',
)
);
Or (probably better) a series of more specific forms like:
Router::connect('?action=show&id=:id',
array(
'controller' => 'features',
'action' => 'view',
),
array(
'id' => '[0-9]+',
)
);
In this case, action and id would be available in $this->request->params in myController (and in the case of a standard like id, there might even be automagic to help!)
Though I'm not sure that the routing elements (:foo) will pick up GET params like that..
Alternatively, you could send everything to one controller anyway, and you should find the GET parameters are listed in $this->request->params['url'], so you can route everything in the controller (to other controllers, I guess).
Doesn't sound pretty either way, but I understand you want to keep some legacy urls running!
By default, when displaying pagination numbers, the url looks like /controller/action/page:number. In my application I have defined a route:
Router::connect('/:categ', array('controller' => 'posts', 'action' => 'index'), array('categ' => '[a-zA-Z]+'));
I want the number link to be something like /:categ/:page.
I've tried with
Router::connectNamed(array('page'));
but has no effect.
Am I missing something?
You must using pagination options with url params:<?php $this->Paginator->options(array('url' => 'some params')); ?>
I have a rails 2.3.5 application where an action acb is changed to pqr and modified so that it works only for "get" method.
To achive this I have used resource route with options like
map.resources :controller, :member => {:pqr => :get}
The original view file has acb_controller_path link in many places. If I change the path in view file as pqr_controller_path it works fine.
Is there a way I can refer acb_controller_path to controller/:id/pqr ?
You're better off changing the view paths to point to your new route, and I think I'm misunderstanding your question a little but depending which way you're trying to do it, you can try something like this I guess?
map.acb_controller '/controller/:id/pqr', :controller => "controller", :action => "pqr"
I have the following routing rule:
match ':controller/:action/:id'
However when I use
<%= link_to "Link", :action => "some_action", :id => 10 %>
Instead of redirecting to "some_action/10" it redirects to "some_action?id=10"
How can I fix that?
P.S. I know I should be using the path methods, but is there a way to avoid them?
As Matchu said, it should work. Try making your catch-all route the first one in routes.rb. If it works then, you'll know there's another route being evaluated first.
If this doesn't work, post your complete routes.rb file.
I made my routes recognize optional path prefixes, but now I want route generation to remember them without me specifying them each time. I'm using the solution presented here:
Creating routes with an optional path prefix
Here are some examples:
Let's say I'm here: { path => "/", :contoller => 'welcome', :action => 'index', :locale => 'en' } then route generation works like this:
events_path #=> "/en/events"
event_path(1) #=> "/en/events/1"
This is exactly what I want, and everything's great.
Now let's consider I'm here: { path => "/fr", :contoller => 'welcome', :action => 'index', :locale => 'fr' } then route generation works like this:
events_path #=> "/en/events"
events_path(1) #=> "/en/events/1"
This is not helping me at all. What it would be natural to have is events_path to remember params[:locale] and generate "/fr/events". Is there any way I can achieve this?
Unless I'm misunderstanding what you're saying the desired behaviour is exactly the one I've written routing_filter for :)
Try using the provided locale filter by installing the plugin and simply adding map.filter(:locale) to your routes.
If that does not help, please email me or send me a message on github.