Magento - 获取当前域而不是基本域

发布于 2024-10-07 20:20:34 字数 155 浏览 3 评论 0原文

我们正在多个域上运行一个 Magento 安装,并使用脚本从数据库中获取信息以帮助用户过滤产品。

在我们的编码中,我们有 $_SERVER 函数调用似乎是商店 1(位于域 1 上)的商店,我想知道需要更改什么才能从商店 2 获取信息(它位于域 2) 上。

We are running one Magento install over multiple domains and are using a script to fetch information from the database to help users filter the products.

In our coding we have the $_SERVER function calling the store which seems to be store 1 (which is on domain 1), I was wondering what I would need to change to fetch the information from store 2 (which is on domain 2).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

生生漫 2024-10-14 20:20:34
echo Mage::getBaseUrl (); 

将仅返回商店 url,即 abc.com/store1。

要获取主商店 URL(域名),请使用以下代码

echo Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB); 

,或者

您可以通过 $_SERVER['HTTP_HOST']; 获取当前域

echo Mage::getBaseUrl (); 

will return the Store url only i.e. abc.com/store1.

In order to get the Main store URL (domain name), use the following code

echo Mage::getBaseUrl (Mage_Core_Model_Store::URL_TYPE_WEB); 

OR

you can get the current domain by the $_SERVER['HTTP_HOST'];

盗心人 2024-10-14 20:20:34

请注意 $_SERVER['SERVER_NAME'] 在 Magento 调度程序 (cron) 任务上不可用(除非你付出一些努力) - 今天才意识到

Be aware that $_SERVER['SERVER_NAME'] is not available on Magento scheduler (cron) tasks (unless you put some effort on it) - just realised that today

听不够的曲调 2024-10-14 20:20:34

首先,$_SERVER不是一个函数,而是一个预定义的变量(关联数组)。一旦您从域 2 访问该网站,$_SERVER['SERVER_NAME'] 将为您提供正确的信息。这完全取决于您从哪个域访问服务器。我目前将其用于我拥有的经销商网站,该网站有很多停放域名。

希望有帮助。

干杯!

First of all, $_SERVER is not a function, but a predefined variable (associative array). Once u access the site from domain 2, $_SERVER['SERVER_NAME'] will give u the right thing. It all depends on which domain you access the server from. I currently use this for a reseller website i have that has a lot of parked domains.

Hope that helps.

Cheers!

多情出卖 2024-10-14 20:20:34

如果您有多个域,那么您可能有多个商店。您无需读取域名来确定哪个商店,只需直接读取商店:

$store = Mage::app()->getStore()

$store 即可获得您需要的所有信息。例如,要检索您在管理员使用中设置的“商店代码”,

$store->getCode()

除了面向对象,因此更容易编写之外,您还可以从管理员完全可配置的域中受益,无需重写您的每次有变化时都编码。

If you have multiple domains then presumably you have multiple stores. Rather than reading the domain to determine which store you can just read the store directly:

$store = Mage::app()->getStore()

$store then has all the information you need. For example, to retrieve the 'store code' that you set in the admin use,

$store->getCode()

As well as being object-orientated and hence easier to write, you benefit from the domains being completely configurable from admin, there will be no need to rewrite your code every time there is a change.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文