Like Codeigniter, Yaf also sets several hook functions to take over or change the program direction as appropriate.
1 |
RouterStartup |
Triggered before routing |
This is the first of the seven events, but some global work should be completed in Bootstrap. |
2 |
RouterShutdown |
Triggered after route ends |
The route must be completed correctly. Otherwise, this event will not be triggered. |
3 |
DispatchLoopStartup |
Triggered before the distribution cycle starts |
|
4 |
PreDispatch |
Triggered before distribution |
If a forward occurs during request processing, this event will be triggered multiple times. |
5 |
PostDispatch |
Triggered after distribution |
At this time, the action has been executed and the view has been rendered. Similar to preDispatch, this event may trigger multiple times. |
6 |
DispatchLoopShutdown |
Triggered after the distribution cycle ends |
This indicates that all the business logic has been completed, but the response has not been sent. |
You can see from the Hook definition that routerStartup is the hook before route initialization. Therefore, you can control the REQUEST_URI suffix in routerStartup and intercept it with a specific suffix.
Example:
# Application \ plugins \ System. php # Yaf_Registry: get ('config')-> application-> url_suffix is the suffix defined in the configuration file, for example :. html class SystemPlugin extends Yaf_Plugin_Abstract {public function routerStartup (Yaf_Request_Abstract $ request, Yaf_Response_Abstract $ response) {if (Yaf_Registry: get ('config')-> application-> url_suffix) {if (strtolower (substr ($ _ SERVER ['request _ URI '],-strlen (Yaf_Registry: get ('config')-> application-> url_suffix ))) = strtolower (Yaf_Registry: get ('config')-> application-> url_suffix )) {$ request-> setRequestUri (substr ($ _ SERVER ['request _ URI '], 0,-strlen (Yaf_Registry: get ('config ') -> application-> url_suffix )));}}}}
Here, the URL is obtained through REQUEST_URI. Other methods are the same. Then, use the uniform URL creation method on the page, and add the suffix when generating the URL.
Implementation of URL Rewrite. htaccess
<IfModule mod_rewrite.c> RewriteEngine on # if a directory or a file exists, use it directlyRewriteCond % {REQUEST_FILENAME }! -FRewriteCond % {REQUEST_FILENAME }! -D # otherwise forward it to index. phpRewriteRule. index. php </IfModule>
SAE
-Rewrite: if (! Is_file ()&&! Is_dir () & path ~ "^/(. *)") Goto "index. php/$1"