Magento - 获取当前域而不是基本域
我们正在多个域上运行一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
将仅返回商店 url,即 abc.com/store1。
要获取主商店 URL(域名),请使用以下代码
,或者
您可以通过
$_SERVER['HTTP_HOST'];
获取当前域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
OR
you can get the current domain by the
$_SERVER['HTTP_HOST'];
请注意 $_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
首先,$_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!
如果您有多个域,那么您可能有多个商店。您无需读取域名来确定哪个商店,只需直接读取商店:
$store
即可获得您需要的所有信息。例如,要检索您在管理员使用中设置的“商店代码”,除了面向对象,因此更容易编写之外,您还可以从管理员完全可配置的域中受益,无需重写您的每次有变化时都编码。
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
then has all the information you need. For example, to retrieve the 'store code' that you set in the admin use,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.