Thursday, February 21, 2013

html link helper with subdomain SubdomainRoute only first routeClass is working correctly

I'm trying to get subdomain links working on my app based on (http://book.cakephp.org/2.0/en/appendices/new-features-in-cakephp-2-0.html#routes-can-return-full-urls )
I have multiple routes which need subdomain functionality in html links but always whichever Route on the top is working correctly..
The rest just creates links with "http://subdomain.domain.com/" always missing the url path...

I think the issue is somewhere at the parent CakeRoute match returns false without returning the the url path because param values are mixed up...

This is my setup:

Latest CakePHP 2.3

app/Config/routes.php
App::uses('SubdomainRoute', 'Route');
Router::connect('/recipe/:slug', array('controller' => 'recipes', 'action' => 'view'), array('pass' => array('slug'), 'routeClass' => 'SubdomainRoute')); = WORKS
Router::connect('/product/:slug', array('controller' => 'products', 'action' => 'view'), array('pass' => array('slug'), 'routeClass' => 'SubdomainRoute')); = DOESNT WORK 
Router::connect('/category/:slug', array('controller' => 'categories', 'action' => 'view'), array('pass' => array('slug'), 'routeClass' => 'SubdomainRoute')); = DOESNT WORK 


app/Lib/Route/SubdomainRoute.php :
<?php
class SubdomainRoute extends CakeRoute {
public function match($params) {
$subdomain = isset($params['subdomain']) ? $params['subdomain'] : '';
unset($params['subdomain']);
$path = parent::match($params);
$domain = Configure::read('Settings.DOMAIN');
if ($subdomain) {
$path = 'http://' . $subdomain . '.' . $domain . $path;
}
return $path;
}
}


template :
<?php echo $this->Html->link($recipe['Recipe']['name'], array('subdomain' => $recipe['User']['slug'], 'controller' => 'recipes', 'action' => 'view', 'slug' => $recipe['Recipe']['slug'])); ?>



Thanks,

Andras

--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
 
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

No comments: