Use cases for generated urls in symfony2?

Based on direct PHP and the Drupal background, I recently learned the structure of Symfony2. I am currently in the book routing chapter. This is probably a simple question.

What are some real world use cases for why you would need to create URLs in a Symfony application? I understand the code, but I had problems defining its practical applications. p>

I mean this section if you need to update.

Thanks as always!

PS The symphony is awesome. :)

+4
source share
4 answers

, URL-, .

, , . , , , URL-, /user/create, /user/edit/(user id) /user/remove/(user id).

, , , URL , . /user/edit/(user id). ,

<a href="/user/edit/<?= $currentUser->getId() ?>">edit this user</a>

, URL? , - "", , , , ""! URL-, "". , , URL-, . Eugh.

, Symfony !

URL- Symfony . , Symfony, , . YAML :

user_edit:
  path:     /user/edit/{userId}
  defaults: { _controller: AppBundle:User:edit }
  requirements:
      userId:  \d+

", - , /user/edit/{userId}, editAction UserController AppBundle, userId . , , userId - ."

, Symfony , URL- . , , , .

, URL- , . , , , , . , , Symfony URL- .

, , Symfony:

<a href="<?= $view['router']->generate('user_edit', ["userId" => $currentUser->getId()]) ?>">edit this user</a>

, , URL, , , , .

+3

, , URL- , 10 Twig. . , :

  • URL-, .
  • "" , (dev, prod...)

, " ", URL- Javascript. Symfony2 Javascript, , FOSJsRoutingBundle.

+2

, .:) , :

URL-:

  • Drupal l(), .
  • , - .

: href .

+1

, , generateUrl , .

, .

return $this->redirect($this->generateUrl('myentity_view', array('id'=> $id)));

twig path, URL .

0
source

All Articles