How symfony2 works and how symfony2 works

Source: Internet
Author: User

How symfony2 works and how symfony2 works

1. routing is a one-to-one ing between program methods and URLs.

In the configuration file, placing frequently accessed routes in front can improve the routing matching efficiency.

2. route matching methods

  • Annotation

Function that allows you to annotate the running status of a method.

Class UserController extends Controller {/*** @ Route ("/user/login") * @ Template () */public function loginAction () {// code }}
  • Router. yml

Common configuration formats of symfony2

The two methods cannot be used at the same time.

3. URL Definition

Static and Dynamic URLs

<? Phpnamespace Scource \ WebBundle \ Controller; use Symfony \ Bundle \ FrameworkBundle \ Controller; use Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Route; use Sensio \ Bundle \ FrameworkExtraBundle \ Template;Use Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ Method ;//Method is used in the following route definition

// Define the total router. If all the routes used in the current controller start with/page/*** @ Route ("/page ") */class DefaultController extends Controller {/*** @ Route ("/{page_num}", defaults = {"page_num": 1 }, requirements = {"page_num" = "\ d +"}) * @ Template () * @ Method ("get") * // The preceding annotations are not useless, it uses annotations to dynamically affect program code. After defining the overall route, you can define only the second-level route when defining the current route. // defaults = {"page_num ": 1} set the default value of page_num to 1 // requirements = {"page_num" = "\ d +"}. The value of page_num must be a number // http: // localhost: 8000/app_dev. Php/page/555 public function indexAction ($ page_num) {$ method = $ this-> getRequest ()-> getMethod (); // return array ('name' => $ page_num);}/*** @ Route ("/test", name = "page_test ") * @ Template () * // name = "page_test" set the route name // use the command line> php app/console router: match/page/test can query the route information of/page/test // http: // localhost: 8000/page/test? Name = world public function testAction () {$ name = $ this-> getRequest ()-> get ('name '); // get the value of the temporary pass parameter return array ('name' => $ name );}}

//////////////

Use Sensio \ Bundle \ FrameworkExtraBundle \ Configuration \ ParamConverter

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.