Yaf video tutorial-routing definition and usage

Source: Internet
Author: User
Today, we will mainly explain how to use the yaf router route. the purpose of routing is to define your own url, which can be easily optimized for users to remember. it is also very helpful for seo, so today we are talking about the yaf routing function. today we mainly explain how to use the yaf router routing. the routing means that you can define your own URLs, the url can be simply optimized for users to remember, and seo is also very helpful. so today we will explain the yaf routing function.

Demo. php plug-in instance code
Class Bootstrap extends Yaf_Bootstrap_Abstract {
Public function _ initConfig (Yaf_Dispatcher $ dispatcher ){
// Var_dump ($ dispatcher-> getRequest ());
$ Config = Yaf_Application: app ()-> getConfig ();
Yaf_Registry: set ("config", $ config );
}


Public function _ initRouter (){
// Configure the route by configuring app. ini
$ Router = Yaf_Dispatcher: getInstance ()-> getRouter ();
$ Router-> addConfig (Yaf_Registry: get ("config")-> routes );
// Configure the route
// $ Route = new Yaf_Route_Supervar ("r ");
// $ Route = new Yaf_Route_Simple ("m", "c", "");
/*
$ Router-> addRoute (
"Paging_example ",
New Yaf_Route_Regex (
"# ^/Index/page/(\ d + )#",
Array ('controller' => "index "),
Array (1 => "page ")
)
);
*/
}


Public function _ initSpaceName (){
$ Loader = Yaf_Loader: getInstance ()-> registerLocalNamespace (array ("Test", "Dum "));
Yaf_Registry: set ("loader", $ loader );
}




Public function _ initPlugin (Yaf_Dispatcher $ dispatcher ){
$ Demo = new DemoPlugin ();
$ Dispatcher-> registerPlugin ($ demo );
}
}
App. ini configuration
[App]
Application. directory = APP_PATH "/app /"
Application. view. ext = "html"
Application. library = APP_PATH "app/library /"
Application. bootstrap = APP_PATH "Bootstrap. php"
Application. dispatcher. catchException = 1
; Custom route
; Order is important
Routes. regex. type = "regex"
Routes. regex. match = "#/list/([^/] *)/([^/] *) #"
Routes. regex. route. controller = index
Routes. regex. route. action = show
R < Application. view. ext = "html"
Application. library = APP_PATH "app/library /"
Application. bootstrap = APP_PATH "Bootstrap. php"
Application. dispatcher. catchException = 1
Outes. regex. map.1 = name
Routes. regex. map.2 = value
; Add a routing protocol named simple
Routes. simple. type = "simple"
Routes. simple. controller = c
Routes. simple. module = m
Routes. simple. action =
; Add a routing protocol named supervar
Routes. supervar. type = "supervar"
Routes. supervar. varname = r
;
; [Product: common]
; The product section is the section that Yaf cares about by default. add a routing protocol named rewrite
; Routes. rewrite. type = "rewrite"
; Routes. rewrite. match = "/product/: name/: value"

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.