How to create a sub-domain in CakePHP?

前端 未结 3 1568
渐次进展
渐次进展 2021-01-06 04:59

CakePHP version-2.5.5

My domain name is http://www.thechatfun.com

Profile page link - http://www.thechatfun.com/users/profile

Chat page

3条回答
  •  [愿得一人]
    2021-01-06 05:34

    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

提交回复
热议问题