When developing a web application, it seems that the link format is too simple, and you want to give a. html suffix for a single URL. In this case, you can directly modify the configuration information in Codeigniter. No direct configuration is found in Yaf, and there are too few materials to search online. So think about how to rewrite the implementation. Like Codeigniter, Yaf also sets several hook functions.
The link format is too simple when you develop the dashboard. you want to add a uniform. html suffix to the URL. In this case, you can directly modify the configuration information in Codeigniter. No direct configuration is found in Yaf, and there are too few materials to search online. So think about how to rewrite the implementation. Like Codeigniter, Yaf also sets several hook functions.
The link format is too simple when you develop the dashboard. you want to add a uniform. html suffix to the URL. In this case, you can directly modify the configuration information in Codeigniter. No direct configuration is found in Yaf, and there are too few materials to search online. So think about how to rewrite the implementation.
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 :. htmlclass 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
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
SAE
- rewrite: if (!is_file() && !is_dir() && path ~ "^/(.*)") goto "index.php/$1"
Original article address: Add a URL suffix for Yaf. Thank you for sharing it.