Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Tweak to Absolute URL generation#3693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
weaverryan merged 2 commits into2.3fromabsolute-urls
Mar 19, 2014
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 23 additions & 25 deletionsbook/routing.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1192,29 +1192,6 @@ In an upcoming section, you'll learn how to generate URLs from inside templates.

For more information, see the documentation for that bundle.

.. index::
single: Routing; Absolute URLs

Generating Absolute URLs
~~~~~~~~~~~~~~~~~~~~~~~~

By default, the router will generate relative URLs (e.g. ``/blog``). To generate
an absolute URL, simply pass ``true`` to the third argument of the ``generate()``
method::

$this->get('router')->generate('blog_show', array('slug' => 'my-blog-post'), true);
// http://www.example.com/blog/my-blog-post

.. note::

The host that's used when generating an absolute URL is the host of
the current ``Request`` object. This is detected automatically based
on server information supplied by PHP. When generating absolute URLs for
scripts run from the command line, you'll need to manually set the desired
host on the ``RequestContext`` object::

$this->get('router')->getContext()->setHost('www.example.com');

.. index::
single: Routing; Generating URLs in a template

Expand All@@ -1227,7 +1204,7 @@ But if you pass extra ones, they will be added to the URI as a query string::
$this->get('router')->generate('blog', array('page' => 2, 'category' => 'Symfony'));
// /blog/2?category=Symfony

Generating URLs from atemplate
Generating URLs from aTemplate
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The most common place to generate a URL is from within a template when linking
Expand All@@ -1250,7 +1227,20 @@ a template helper function:
Read this blog post.
</a>

Absolute URLs can also be generated.
.. index::
single: Routing; Absolute URLs

Generating Absolute URLs
~~~~~~~~~~~~~~~~~~~~~~~~

By default, the router will generate relative URLs (e.g. ``/blog``). From
a controller, simply pass ``true`` to the third argument of the ``generateUrl()``
method::

$this->generateUrl('blog_show', array('slug' => 'my-blog-post'), true);
// http://www.example.com/blog/my-blog-post

From a template, it looks like this:

.. configuration-block::

Expand All@@ -1268,6 +1258,14 @@ Absolute URLs can also be generated.
Read this blog post.
</a>

.. note::

The host that's used when generating an absolute URL is the host of
the current ``Request`` object. This is detected automatically. But if
you generate absolute URLs for scripts run from the command line, this
won't work. But don't worry! Just see :doc:`/cookbook/console/sending_emails`
for details.

Summary
-------

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp