Yaf的路由器, 负责分析请求中的request uri, 得出目标模板, 控制器, 动作.
在PHP5.3之后, 打开yaf.use_namespace的情况下, 也可以使用 Yaf\Router
final Yaf_Router {protected array_routes;protected string_current_route;public Yaf_Router addRoute ( string $name ,
Yaf_Route_Interface $route );public boolean addConfig ( Yaf_Config_Abstract $routes_config );public array getRoutes ( void );public array getRoute ( string $name );public string getCurrentRoute ( void );public boolean route ( Yaf_Request_Abstract $request );public boolean isModuleName ( string $name );
}
_routes路由器已有的路由协议栈, 默认的栈底总是名为"default"的Yaf_Route_Static路由协议的实例.
_current_route在路由成功后, 路由生效的路由协议名
Yaf的路由需要Web服务器把非静态资源的请求都转发到入口脚本, 以下是几种常见Web服务器的重写配置.
Apache:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
Nginx:
server {
listen 80;
server_name yourdomain.com;
root document_root;
index index.php index.html;
if (!-e $request_filename) {
rewrite ^/(.*) /index.php/$1 last;
}
}
Lighttpd:
url.rewrite-once = ( ".*\?(.*)$" => "/index.php?$1", ".*\.(js|ico|gif|jpg|png|css|html)$" => "$0", "" => "/index.php" )