Hi everyone i have just read this post;
http://mark-story.com/posts/view/using-custom-route-classes-in-cakephp

The post give me hopes that the custom route class with helps with the
subdomains issues, so i write a SubdomainRouter its having some
problems with the link building…

Could anyone take a look to the code?

#config/routes.php
App::import(‘Lib’, ‘SubdomainRoute’);
define(‘MYDOMAIN’, ‘domain.com.ar’);

$ops=array(‘routeClass’ => ‘SubdomainRoute’);
Router::connect(’/:subdomain/’, array(‘controller’=>‘pages’,‘action’
=> ‘display’,‘home’),$ops);
Router::connect(’/:subdomain/:controller’, array(‘action’ => ‘index’),
$ops);
Router::connect(’/:subdomain/:controller/:action/*’,array(),$ops);

   1. libs/subdomain_route.php
      class SubdomainRoute extends CakeRoute { function parse($url)
{ if(defined(‘MYDOMAIN’)){ $subdomain = substr( env(“HTTP_HOST”), 0,
strpos(env(“HTTP_HOST”), “.”.MYDOMAIN) ); $url=’/’.$subdomain.$url; }

return parent::parse($url); }

function _writeUrl($params)
{ $params[‘subdomain’]=isset($params[‘subdomain’])?
strtolower($params[‘subdomain’]):‘www’;

$out=parent::_writeUrl($params);

if(!defined(‘MYDOMAIN’)) return $out;

$out=substr($out,strpos($out, ‘/’)+1); $out=substr($out,strpos($out,
‘/’));

return ‘http://’.$params[‘subdomain’].’.’.MYDOMAIN.$out; }
}

when i access to some url like;
http://sub.domain.com/
or
http://sub.domain.com/pages/display/test

everything its okey

but when i build a link using;
echo $this->Html-
>link(‘test’,array(‘controller’=>‘pages’,‘action’=>‘display’,‘home’,‘subdomain’=>‘www’));

it outputs this url; /app_path/http:/www.domain.com

any ideas?

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 [email protected]
To unsubscribe from this group, send email to
[email protected] For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en

Reply via email to