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
Function that allows you to annotate the running status of a method.
Class UserController extends Controller {/*** @ Route ("/user/login") * @ Template () */public function loginAction () {// code }}
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