issue and I didn't want to complicate by asking two questions in one
thread. So here's "Round 2" :-)
###
Okay, so I know that 1.3 eliminated the old plugin routing that
automagically made it the double reference to plugins/controllers
disappear. Ie. /admin/projects/projects/view/1 was automagically /
admin/projects/view/1.
So I've been trying to get it back for like a week now, and have it
pretty well done, but something very strange is going on and I was
wondering if anyone might have some ideas to push me in another
direction. And this specifically relates to needing html->link to
output the right href attribute to match my routing in Round 1 of this
message.
Situation Summary : I took some points from Mark Story's blog and the
great custom parse routing explanation he gave,
http://mark-story.com/posts/view/using-custom-route-classes-in-cakephp
and tried to re-fashion it into a "match" routing so that html->link
will output the right href attributes. It works in almost all cases
except when I am in a sub-controller of a plugin and linking back to
the main controller which has the same name as the plugin. For
example, I'm in the "projects" plugin, looking at "/admin/projects/
project_issues/view/1" and html-> link should be pointing back to "/
admin/projects/" or "/admin/projects/index" and instead it points to "/
admin/projects/projects/index" which doesn't work because some of my
other routing (referenced in Round 1) is set to eliminate the double
plugin/controller reference. In all other cases, and even on other
pages, the links work. The same link exact link even (in my main
navigation for instance) works on every other page, except when I am
in this sub controller of the project.
Routing codes :
/app/config/routes.php
App::import('Lib', 'HtmlLinkRewrite');
Router::connect('/:slug', array(), array('routeClass' =>
'HtmlLinkRewrite'));
/app/libs/routes/html_link_rewrite.php
<?php
class HtmlLinkRewrite extends CakeRoute {
function match($url) {
if ($url['plugin'] == $url['controller']) {
unset($url['plugin']);
$output = array();
$named = array();
foreach ($url as $key => $value) {
if (!empty($url[0])) {
$output[3] = $url[0];
}
if ($key == 'admin') {
$output[0] = $key;
} else if ($key == 'controller') {
$output[1] = $value;
} else if ($key == 'action') {
$output[2] = $value;
} else {
$named[] = $key.':'.$value;
}
}
ksort($output);
$output = implode('/', $output);
$output = $output.'/'.implode('/', $named);
return $output;
}
$url = parent::match($url);
if(empty($url)) {
return false;
}
return false;
}
}
?>
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment