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

Add the possibility to prefix URLs and routes name#9159

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

Closed
ismail1432 wants to merge1 commit intosymfony:4.0fromismail1432:patch-2
Closed
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
31 changes: 31 additions & 0 deletionsrouting.rst
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -126,6 +126,8 @@ Whenever you have a ``{placeholder}`` in your route path, that portion becomes a
wildcard: it matches *any* value. Your controller can now *also* have an argument
called ``$placeholder`` (the wildcard and argument names *must* match).



Each route also has an internal name: ``blog_list`` and ``blog_show``. These can
be anything (as long as each is unique) and don't have any meaning yet. You'll
use them later to :ref:`generate URLs <routing-generate>`.
Expand DownExpand Up@@ -241,6 +243,35 @@ URL Route Parameters
To learn about other route requirements - like HTTP method, hostname and dynamic
expressions - see :doc:`/routing/requirements`.

Prefix all controller route names and URLs
------------------------------------------

You have the possibility to prefix all routes names and URLs used by the action methods of a controller with the ``@Route`` annotation.

Add a name property to the ``@Route`` annotation of the controller class and that will be considered the prefix of all route names

.. code-block:: php

use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
//prefix all URLs of this controller's action method with /blog and routes name with blog_
/**
* @Route("/blog", name="blog_")
*/
class BlogController extends Controller
{
/**
* @Route("/", defaults={"page": "1"}, name="index")
*/
public function indexAction($page, $_format) { ... }

/**
* @Route("/posts/{slug}", name="post")
*/
public function showAction(Post $post) { ... }
}

In this example, the URL of the index action will be ``/blog/`` and ``/blog/posts/``... and the URL of the show action will be /blog/posts/... It's the same logic for the routes name that will be ``blog_index`` and ``blog_post``.

Giving {placeholders} a Default Value
-------------------------------------

Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp