到底是什么baseUrl [英] What exactly is a baseUrl

查看:1933
本文介绍了到底是什么baseUrl的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了一段时间来尝试了解baseUrl是什么(通过学习Zend Framework),但是令人惊讶的是,对于这样一个无处不在的实用程序,没有一个专家或博主甚至试图定义baseUrl以使学习者拥有一个关于它的想法。他们都假设您知道它是什么,然后继续进行推导,每个人都使用自己的方法得出自己的结果。从到目前为止我读到的内容:

I have spent sometime trying to understand what a baseUrl is(from learning Zend Framework), but it's surprising that for such a ubiquitous utility, not a single "expert" or blogger has even attempted to define baseUrl so that a learner has an idea what it is about. They all assume you know what it is and then proceed to derive it, each one employing his own method to arrive at his own result. From what I'd read so far:

有人认为这是一个Homepage-Url,这是我自然认为的(顾名思义) ,由 $ _ SERVER [ HTTP_HOST] $ _ SERVER [ SERVER_NAME] 访问,但令人惊讶的是,这些似乎

Some think it is a Homepage-Url, which is what I'd naturally think it is(as implied from the name), to be accessed by $_SERVER["HTTP_HOST"] or $_SERVER["SERVER_NAME"] but surprisingly these seem to be in the minority.

有人认为这是当前页面, $ _ SERVER [ REQUEST_URI] $ _ SERVER [ PHP_SELF] 附加到服务器名称

Some think it is a current page to be accessed by $_SERVER["REQUEST_URI"] or $_SERVER["PHP_SELF"] appended to server-name

,而其他人则认为它可以是任何以上内容或与此相关的任何网址(嗯,至少这是我的印象),具体取决于用户希望使用它的方式。

while others think it can be any of the above or any url for that matter(well, at least that's the impression I get), depending on how the user wants to use it.

所以有人可以请在不假设我也是专家的情况下,确切解释baseUrl是什么,以及为什么可能需要它。谢谢。

So can someone please explain exactly what a baseUrl is, without assuming I'm also "expert" and why I might need it. Thank you.

编辑:应该在大多数Zend项目上自动设置baseUrl,但显然不是我设置的。即使我执行 echo $ this-> baseUrl() var_dump($ this-> baseUrl()),我什么也没得到。所以我真的不知道这个实用工具是什么。

The baseUrl is supposed to be automatically set on most Zend projects, but apparently not in my case. Even when I do an echo $this->baseUrl() or var_dump($this->baseUrl()), I get nothing. So I really have no idea what this utility is about.

推荐答案

为什么需要一个<$ c的简短答案$ c> baseUrl()工具是这样的:

The short answer for why you need to have a baseUrl() facility is this:

在哪里部署应用程序应该是配置问题,而不是核心应用程序功能问题

在很多情况下,甚至在大多数情况下,应用程序的基本URL就是 $ _ SERVER [ 'HTTP_HOST'] $ _ SERVER ['SERVER_NAME']

In many - perhaps even most - cases, the base-url of the application will simply be $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME'].

但这并非总是如此。

最容易考虑的示例是具有常规功能的标准网站页面:

The easiest example to consider is a standard website that has the usual pages:


  • http://example.com/

  • http://example.com/contact

  • http:// example .com / about

  • //等

  • http://example.com/
  • http://example.com/contact
  • http://example.com/about
  • // etc

现在您编写(或以OSS软件包的形式购买或下载)要在URL下部署的博客应用程序:

Now you write (or buy or download as an OSS package) a blog application that you would like to deploy under the url:

http://example.com/blog

博客可能具有以下链接:

The blog could have links like:


  • http://example.com/blog/post/my-post-slug

  • http://example.com/blog/categories/some-category

  • // etc

  • http://example.com/blog/post/my-post-slug
  • http://example.com/blog/categories/some-category
  • //etc

所有这些链接均位于 / blog下

All these links reside under /blog.

博客应用程序本身应该与博客内部的链接/页面/路由有关。尽管您的博客模板很可能包含指向网站其余部分的页眉/页脚链接,但其余的核心博客应用程序功能应该不必了解网站的其余部分。不知何故,博客应用程序需要知道,当他生成指向博客文章和博客类别以及他所有其他与博客有关的页面的链接时,它们都必须以 http://example.com/blog <作为前缀。 / code>。

The blog application itself should be concerned only with links/pages/routing inside the blog. Though your blog templates may very well contain header/footer links back to the rest of the site, the rest of the core blog application functionality should not have to know about of the rest of your site. Somehow, the blog application needs to know that when he generates links to blog posts and blog categories and all his other blog-related pages, they all must be prefixed with http://example.com/blog.

$ _ SERVER ['HTTP_HOST'] $ _ SERVER ['SERVER_NAME'] 不反映此环境/部署信息。在生成链接时使用基本URL值配置(!)应用程序,并持续使用某种 baseUrl()函数(使用此配置)是保持链接状态的一种好方法您的核心应用程序功能侧重于自己的业务,而不是外部部署因素。

The values $_SERVER['HTTP_HOST'] or $_SERVER['SERVER_NAME'] do not reflect this environment/deployment information. Configuring (!) the app with a base-url value and consistently using some kind of baseUrl() function (that consumes this config) when generating links is a good way to keep your core application functionality focused on its own business and not on external deployment factors.

这篇关于到底是什么baseUrl的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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