I would like to be able to match a URL like this
www.site.com/cc/[action-name-first-part].12345.[action-name-second-part]
Basically the resulting action would be a concatenation of the 2 action name.
My current route looks like this
$ccRoute = new Zend_Controller_Router_Route_Regex(
'cc/([^.]).([^.]).([^.]*)',
array('controller' => 'cc'),
array('action-first-part' => 1, 'arbitrary-number' => 2, 'action-second-part' => 3)
);
this partner matches fine. but with the third argument (mapping argument), how can I concat the 1 and 3 index and just pass the correct action to the controller.
Thanks.
As far as I remember, you cannot do this with the regex routes. However, it's quite trivial to make a new route class that can do this.
Here is a quick answer on how to make your own route class.
how to get dynamic URL like mydomain.com/username using zend framework
Related
I want to rewrite my url in YII to make url seo friendly .
The URL in my current system is
http://mysite/recipe/recipedetail/1
and i want to make it like
http://mysite/recipename
how i can do it
i am trying ot use rule but they are not working my rules in config/main files are
'url.rules' => array(
'recipe/<recipename:([A-Za-z0-9-]+)>/' => 'recipe/recipedetail/<recipename:\w+>/',
),
You may try this:
'recipe/recipedetail/<id:\d+>'=>'recipe/recipedetail',
A route part of rule must not contain parameters, but must be in controller/action format:
'url.rules' => array(
'recipe/<recipename:[A-Za-z0-9-]+>/' => 'recipe/recipedetail',
),
All named parameters will be available in $_GET, so inside your controller action you can access recipename value with $_GET['recipename]`.
Additionaly, please mention that you must not wrap parameter pattern ([A-Za-z0-9-]+ in your case) in brackets.
I guess you're missing var_name in your url
'recipe/<recipename:([A-Za-z0-9-]+)>/' => 'recipe/recipedetail/var_name/<recipename:\w+>/'
get the recipename inside your controller using var_name
I'm new with Kohana and finding their documentation to be lacking (lots of incomplete writings, lots of broken links, etc.). I just want to create a route like so:
Route::set('test1', 'blah/<id>')
->defaults(array(
'controller' => 'Blah',
'action' => 'foo',
));
So if the URL is localhost/blah/8342342 it will run through this controller and action. The problem is I get a 404 error. If I change the URI in the Route::set to be blah/foo/<id> it works fine. I only want the /blah/ directory though, not 'blah/foo'. Is this possible or do you need to have both the controller and action in the URL?
Another question, does the first directory in your URI (in this case /blah) HAVE to match the controller name? For example, if the first directory in the URI is "blah/", does that mean my controller must be named "Blah.php"? From my tests it seems that this is the case, but I don't know why it would be set up that way. What if I wanted the URI "contact/" to go through controller Blah?
I'd like to set up some kind of hierarchical routing in Kohana 3.0.9. The routing should support pages and sub-pages, which could look something like this:
URL called: http://example.com/company/contact/
Possible Route: <page>(/<subpage>(/<action>))
The problem with above mentioned route is that it only supports a hierarchy with two levels. If the site needed to be able to handle "sub-sub-pages" like http://example.com/company/contact/sub, I would have to change the route.
Also, I'd like one single page controller to handle the request. It could, for example, accept company/contact/sub as a string parameter. I'm aware of the <directory> key and I'm not planning to use it.
Is there any way to make the route "compatible" with unlimited nested pages?
Thanks in advance for your answers.
If you look at the ROUTING section, you can create custom REGEX patterns.
(read here) http://kohanaframework.org/guide/kohana/routing
By default, routing "parameters" removes punctuation.
You can setup a regex to accept "/".
Then you can grab the last parameter and explode it with
$pieces = explode("/", $pizza);
Example:
http://example.com/company/contact/subpage/subsubpage/action
Route::set('multilevel', '(<controller>(/<page_levels>/<action>))'
, array('page_levels' => '.*'))
->defaults(array(
'controller' => 'page_controller',
'action' => 'index',
));
Doublecheck the REGEX, but basically it grabs all "/" except the very last one (which should be your ACTION parameter separator.
In your ACTION_[action] function (in Controller_Contact for this example),
you would then call
$page_levels = Request::instance()->param('page_levels');
$page_array = explode("/",$page_levels);
This should get you
$page_array = array ( [1] => 'contact',
[2] => 'subpage',
[3] => 'subsubpage')
I want that users can surf to http://www.yyy.com/xxx for xxx being a parameter. and so with www.yyy.com/xxx/zzz . I have following routing which works fine:
Router::connect('/:town', array('controller'=>'places', 'action'=>'index'), array('pass' => array('town')));
Router::connect('/:town/:category', array('controller'=>'places', 'action'=>'index'), array('pass' => array('town', 'category')));
But when I want tot surf to a different controller example www.yyy.com/differentcontroller/add it goes back to the places controller unless I make a routing for it...
any ideas?
The second rule on your routing list is simply looking for two sets of any combinations of characters after the domain name and treating the first as a town and the second as a category. As a result it mistakenly parses 'differentcontroller' as a town name and 'add' as a category. If you want to keep this URL structure then you'll need to add more specific routes to your routing file to cover situations like the 'add' route, or consider changing your existing URL layout to something more specific, like:
Router::connect('/places/:town', array('controller'=>'places', 'action'=>'index'), array('pass' => array('town')));
Router::connect('/places/:town/:category', array('controller'=>'places', 'action'=>'index'), array('pass' => array('town', 'category')));
My memories about cake routing is quite rusty, but you can use :controller/:action as a rule to make cake look for a valid controller/action pair, if I remember correctly.
I've got a question considering Zend_Controller_Router. I'm using a a modular-structure in my application. The application is built upon Zend-Framework. The normal Routes are like this:
/modulename/actionname/
Since I always use an IndexController within my modules, it's not necessary to provide it in the url. Now I am able to append params like this:
/modulename/actionname/paramkey/paramvalue/paramkey/paramvalue
So this is normal in ZF, I guess. But in some cases I don't want to provide a paramkey within the url. For example I want a blog-title to be shown within the url. Of course this is intended for SEO:
/blog/show/id/6/this-is-the-blog-title
In this case, blog is the module, show is the action. id is a paramkey and 6 is the id of the blogpost I want to show. this-is-the-blog-title is of course the headline of the blogpost with the id 6. The problem is, that if I do use the assemble()-method of the router like this:
assemble(array('module' =>'blog',
'action' => 'show',
'id' => $row['blog_id'],
$row['blog_headline_de'] . '.html'));
the url results in:
blog/show/id/6/0/this-is-the-blog-title.html
As you can see a 0 is inserted as a key. But I want this 0 to be omitted. I tried this by using the blogtitle as key, like this:
assemble(array('module' =>'blog',
'action' => 'show',
'id' => $row['blog_id'],
$row['blog_headline_de'] . '.html' => ''));
This results in:
blog/show/id/6/this-is-the-blog-title.html/
Now the 0 is omitted, but I've got the slash at the end.
Do you have any solution to get an url without 0 as key and without an ending slash?
Regards,
Alex
You might want to use a custom route for this:
$router->addRoute(
'blogentry',
new Zend_Controller_Router_Route('blog/show/:id/:title',
array('controller' => 'index', 'module' => 'blog'
'action' => 'info'))
);
And call your assemble with the route as second parameter. See the Zend_Controller_Router_Route section of the documentation for more details (they even provide examples with assemble).
Or in a more general way:
$router->addRoute(
'generalseo',
new Zend_Controller_Router_Route(':module/:action/:id/:title',
array('controller' => 'index'))
);