仅为两个控制器分配不同的域 [英] Assign different domain for two controllers only

查看:27
本文介绍了仅为两个控制器分配不同的域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是旧版 Yii (v1),我只需要为两个控制器分配不同的域.

I am using the old Yii (v1), and I need to assign a different domain to two controllers only.

所以我有一堆控制器 - HomeController.php、CategoryController.php、GuestbookController.php、ShopController.php、ProfileController.php,它们都使用域 aaaaa.com,但我需要这些控制器 ShopController.php和 ProfileController.php 仅适用于域 bbbbb.com.

So I have a bunch of controllers - HomeController.php, CategoryController.php, GuestbookController.php, ShopController.php, ProfileController.php, all of them works with a domain aaaaa.com, but I need that controllers ShopController.php and ProfileController.php would work only with domain bbbbb.com.

附言当用户单击我的个人资料"链接或商店"时,域将更改为 bbbbb.com,当用户单击主页"、类别"、留言簿"时,域将更改为 aaaaa.com当用户输入 URL aaaaa.com 时,它会转到主页"(HomeController.php)(就像现在一样),当他输入 bbbbb.com 时,它会转到商店"(ShopController.php)

P.S. When user clicks "My Profile" link or "Shop" the domain changes to bbbbb.com, when user clicks "Home", "Categorys", "Guestbook" the domain changes to aaaaa.com And when user enters URL aaaaa.com it goes to "Home" (HomeController.php) (as it is now) and when he enters bbbbb.com it goes to "Shop" (ShopController.php)

一个页面,一个导航栏.

Its all one page with one Navigation bar.

推荐答案

因此,您希望应用程序的不同部分由两个不同的域提供服务,这两个域都是指向同一应用程序的同一服务器上的虚拟主机.

So you want different parts of your application to be served from two different domains that are both virtual hosts on the same server pointing to the same application.

您可以使用 Yii 的重写规则轻松做到这一点,因为您可以在定义它们时指定完整主机.

You can easily do that with Yii's rewrite rules because you can specify full host when defining them.

这是我的应用程序中的一个示例,用于happyanalytics"工具和happyseotools"博客:

This is an example from my application that is used for both the "happyanalytics" tool as for the "happyseotools" blog:

'urlManager'=>array(
    'urlFormat'=>'path',
    'urlSuffix'=>'/',
    'showScriptName'=>false,
    'rules'=>array(

        'http://'._HOST_HAPPYANALYTICS_.'/' => '/analytics/default/index',
        'http://'._HOST_HAPPYANALYTICS_.'/tour/' => '/analytics/default/tour',
        'http://'._HOST_HAPPYANALYTICS_.'/pricing/' => '/analytics/default/pricing',
        'http://'._HOST_HAPPYANALYTICS_.'/support/' => '/analytics/default/support',
        'http://'._HOST_HAPPYANALYTICS_.'/login/' => '/analytics/default/login',
        'http://'._HOST_HAPPYANALYTICS_.'/forgot_password/' => '/analytics/default/forgot_password',
        'http://'._HOST_HAPPYANALYTICS_.'/signup/' => '/analytics/default/register',
        'http://'._HOST_HAPPYANALYTICS_.'/dashboard/' => '/analytics/dashboard/index',
        'http://'._HOST_HAPPYANALYTICS_.'/dashboard/website/<id_website>/<action:(visits|keywords|pages|debug|realtime|configuration|trackingCode)>/' => '/analytics/dashboard/<action>',
        'http://'._HOST_HAPPYANALYTICS_.'/dashboard/website/<id_website>/' => '/analytics/dashboard/website',
        'http://'._HOST_HAPPYANALYTICS_.'/dashboard/<action>/*' => '/analytics/dashboard/<action>',


        'http://'._HOST_HAPPYSEOTOOLS_.'/' => 'site/index',
        'http://'._HOST_HAPPYSEOTOOLS_.'/about/' => 'site/about',
        'http://'._HOST_HAPPYSEOTOOLS_.'/contact/' => 'site/contact',
        'http://'._HOST_HAPPYSEOTOOLS_.'/smile.gif' => 'site/tracker',
        'http://'._HOST_HAPPYSEOTOOLS_.'/subscription/*' => 'site/subscription',


        'http://'._HOST_HAPPYSEOTOOLS_.'/blog/posts/<tag:.*?>/'=>'/blog/post/index',
        'http://'._HOST_HAPPYSEOTOOLS_.'/blog/'=>'/blog/post/index',
        'http://'._HOST_HAPPYSEOTOOLS_.'/blog/<slug>/'=>'/blog/post/view',

    ),
),

正如您想象的那样,我之前已将域定义为常量,而不必一直重复它们.也可能有更清洁的解决方案,但这个解决方案有效:)

As you imagine I have previously defined the domains as constants to not have to repeat them all the time. Also there might be a cleaner solution but this one works :)

这篇关于仅为两个控制器分配不同的域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆