Objective
Laravel 5 is used here.
PHP Laravel routing is strong, but also because of this, not unified and easy to clutter. For example, in the route can be directly written method operation (destruction encapsulation AH)
The following are examples of individual learning, not for reference
Examples of use rules for direct method calls and routing addresses in routing
/** * Define a/hi address and return to Hi's view*/Route:: Get ('/hi ',function(){ returnView::make ("Hi");});/** * Define a/hello address with parameters, the default reference value for Robin * address access such as:/hello/myname*/Route:: Get ("/hello/{name?}",function($name= "Robin"){ return"Hello".$name;});/** * Define an address:/test/2222 * Use regular match parameter ID*/Route:: Get ("/test1/{id}",function($id) { return"ID value =".$id;})->where ("id", "\d+");/** * Define an address:/test2/123/robin * Match multiple parameters with regular*/Route:: Get ("/test2/{id}/{name}",function($id,$name){ return"ID =".$id. ", Name =".$name;})->where (["id" = "\d+", "name" and "=" [a-za-z]+ "]);/** * Define an/as/my address, add an alias of MM to this route*/Route:: Get ("/as/my", ["as" = "MM",function(){ //Enter the name of the current route, if the route does not give the specified alias, returns a null value returnRoute::currentroutename ();}]);//------------------------------------------------------------------//Test post submission//----------------------------- -------------------------------------Route::get ("/test",function(){ returnView::make ("Test");}); Route::p ost ("/test3",function(){ //Get POST Test text box input value//return $_post["test"]; Get all post content//return Input::all (); Gets the input value of the specified text box returnInput::get ("Test");});//------------------------------------------------------------------//test pre-defined PID for integer//-------------------------- ----------------------------------------$router->pattern ("pid", "\d+"); Route:: Get ("/test4/{pid}",function($pid) { return"Pattern ID =".$pid;});
Of course, it also has some before, after some of the things, here will not write.
Example of routing using controller
/** * Use Conntroller*/Route:: Get ("/test5", ["as" = "Test5", "uses" = "[email protected]"]);/** * Using controller redirection*/Route: Get ("/test6", ["as" = "Test6", "uses" = "[email protected]"]);/** * Redirect of Route*/Route:: Get ("Test7",function(){ returnRedirect::to ("Test5");});/** * Use Controller to get the name of the current route, named: Mytest8*/Route:: Get ("Test8", ["as" = "Mytest8", "uses" = "[email protected]"]);/** * Use a get start before using Controller * Controller method*/Route:: Controller ("/my/test", "My\mytestcontroller");//------------------------------------------------------------------//Controller group//joins the prefix my2, It means that all the routing addresses in the My2 start with a////For example: http://localhost/my/add//------------------------------------------------------------ ------Route::group (["prefix" = "my2"],function() {Route:: Controller ("/", "My\mytest2controller");});
[PHP]-Laravel-route routing