fuelphp, it can be accessed by default/controller_name/function_name this way, or by custom routing.
The routing configuration is in the/fuel/app/config/routes.php file.
One, the simplest route setting, the key value pair form.
return Array ( ' article ' = ' article/index ', ' article/add ' = ' article/create ', ' Article/edit ' = ' Article/edit ', );
The key name is the content entered in the URL, and the corresponding value is the method in the requested controller.
Second, add some rules to the route
:any |
Can match any character, but cannot be empty |
:everything |
Match any character |
:segment |
Match part of the URL, this part can be any character, |
:num |
Match any number |
: Alpha |
Match Greek alphabet |
:alnum |
Match any letter and number |
return Array ( ' article/(: any) ' = ' article/indexxxxx ', ' article (: everything) ' + ' article/add ', ' (: segment)/article ' = ' test/article ',
' (: Segment) article ' = ' test1/article ', ' (\d{2})/article '
‘blog/:year/:month/:id‘ ‘blog/entry‘,
);
Three, according to different request way, the URL route to the controller method, there is get, POST, DELETE and so on.
return Array ( Array (arraynewarraynewarray Newtrue)) ;
This can also be used in conjunction with the above rules.
Four, set the name of the route
return Array ( array(' Admin/overview ', ' name ' = ' Admin_overview '), );
Static page, you can use the route name to achieve click Jump
Echo Html::anchor (Router::get (' Admin_overview '), ' overview ');
<a href= "{router::get (' Admin_overview ')}" >Overview</a>
Five, the core directory of the Route class
1. Add ($path, $options = null, $prepend = false, $case _sensitive = null) add a route
Methods for $path the controller that the route points to
$options parameters in a route
$prepend true route ready for loaded routes
$case whether _sensitive is case sensitive
Router::add (' This/that ', ' something/else '); // a simple key-value pair similar to one
2. Get ($name, $named _params = array()) gets the route through the defined route name
$name a defined route name
$named _params Routing Parameters
//1. return Array(' Thread/(? P<thread_id>\d+?) /post ' =Array(' Post ', ' name ' = ' post '),); //depending on the route defined above, these will return ' Thread/1/post ': EchoRouter::get (' Post ',Array(' thread_id ' = 1)); EchoRouter::get (' Post ',Array(' $ ' = 1)); EchoRouter::get (' Post ',Array(1)); //2. return Array(' country/(? P<country>\d+?) /state/(? P<state>\d+?) /location ' =Array(' Location ', ' name ' = ' location '),); //depending on the route defined above, these will return ' country/japan/state/tokyo/location ': EchoRouter::get (' Location ',Array(' Country ' = ' Japan ', ' state ' = ' Tokyo ')); EchoRouter::get (' Location ',Array(' $ ' = ' Japan ', ' $ ' = ' Tokyo ')); EchoRouter::get (' Location ',Array(' Japan ', ' Tokyo ')); EchoRouter::get (' Location ',Array(' Country ' = ' Japan ', ' Tokyo ')); EchoRouter::get (' Location ',Array(' $ ' = ' Japan ', ' Tokyo ');
3. Delete ($path, $case _sensitive = null) to delete a defined route
$path Route URL
$case whether _sensitive is case sensitive
// remove route ' this/that ' Router::d elete (' this/that '); // Remove routes ' this/that ' and ' Some/other ' Router::d elete (array(' This/that ', ' Some/other ' )); // Set route is case-sensitive true); // Remove all routes for module controller Router::d elete (' Module/controller (: Any) ');
Fuelphp Series (ii)------route Routing