CakePHP version-2.5.5
My domain name is http://www.thechatfun.com
Profile page link - http://www.thechatfun.com/users/profile
Chat page
Follow your context, inside this directory: /lib/Cake/Routing/Route
, create file SubdomainRoute.php
with content:
class SubdomainRoute extends CakeRoute {
public function match($params) {
$subdomain = isset($params['subdomain']) ? $params['subdomain'] : null;
unset($params['subdomain']);
$path = parent::match($params);
if ($subdomain) {
$path = 'http://' . $subdomain . '.thechatfun.com' . $path;
}
return $path;
}
}
When creating links you could do the following to make links pointing at other subdomains.
echo $this->Html->link(
'Profile',
array('subdomain' => 'profile', 'controller' => 'Users', 'action' => 'profile')
);
echo $this->Html->link(
'Chats',
array('subdomain' => 'chat', 'controller' => 'Chats', 'action' => 'index')
);
Reference: http://book.cakephp.org/2.0/en/appendices/new-features-in-cakephp-2-0.html#routes-can-return-full-urls