【问题标题】:CakePhp and subdomain routingCakePhp 和子域路由
【发布时间】:2015-05-31 16:12:12
【问题描述】:

我正在尝试让子域在我的网站上运行,但是,我仍然无法生成指向子域的链接...

我使用了我在网上找到的代码:

<?php

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 . '.localhost' . $path;
        }
        return $path;
    }
}

但这对我不起作用。有人试图找到解决方案并得到一个吗?谢谢!

【问题讨论】:

    标签: cakephp routing subdomain


    【解决方案1】:

    迟到总比没有好,但要使用上述代码,您必须转到 app/Config/routes.php 并使用该类:

    App::uses('SubdomainRoute', 'Routing/Route');
    

    以及将其添加到您的路线中:

    Router::connect( '/:controller/:action/*', 
        [ 'controller' => 'test' ],
        [ 'routeClass' => 'SubdomainRoute' ]
    );
    

    希望这可以帮助...某人:)

    【讨论】:

      猜你喜欢
      • 2012-04-04
      • 1970-01-01
      • 1970-01-01
      • 2018-03-01
      • 1970-01-01
      • 2011-07-18
      • 2011-04-09
      • 2014-02-27
      • 2017-11-17
      相关资源
      最近更新 更多