texnder / routex
PHP框架的轻量级快速路由系统
Requires
- texnder/aditex: 1.0.*
This package is auto-updated.
Last update: 2024-09-26 23:07:50 UTC
README
PHP框架的轻量级快速路由系统
安装
使用composer安装此库。
syntax:
composer require texnder/routex
Routex响应
要获取客户端响应数据,创建[Routex\http\Response类]的新实例并调用其getResponse方法。Routex\http\Response有[Routex\http\Request类]的依赖。因此,通过创建此实例或简单使用aditex依赖注入器创建[Routex\http\Response类]。Routex依赖于aditex,这意味着在您使用composer安装Routex时,它将自动安装。
清洁URL
使用routex库,您可以编写应用程序页面的清洁URL。它易于使用且速度快。它为您的网站提供专业的外观,并有助于您在谷歌搜索中排名更高。清洁URL在数字营销和搜索引擎优化(SEO)方面非常有帮助。
定义自己的路由
Routex为定义应用程序中每个页面的自定义URL提供完全的自由。如果客户端请求与应用程序中定义的URL不同,客户端将获得[404 http错误]响应。
syntax:
use Routex\Route;
// for get requests
Route::get('my-custom-url/{key}/$_GET-key-in-curly-braces/{id}', 'controller@method');
or
Route::get('my-custom-url/{key}/$_GET-key-in-curly-braces/{id}', function(){
return view('ViewName(without extension and use [.] for directory separation)');
});
or
Route::get('my-custom-url/{key}/$_GET-key-in-curly-braces/{id}', function(){
// valid codes..
return "hello world";
});
// for post request
Route::post('my-custom-url', 'controller@method');
or
Route::post('my-custom-url', function(){
return view('ViewName(without extension and use [.] for directory separation)');
});
or
Route::post('my-custom-url', function(){
// valid codes..
return "hello world";
});
创建路由实例
创建新实例,并将资源目录路径和视图文件扩展名([.html]或[.php],默认为[.php])作为构造函数的参数传递。
syntax:
Routex\Route(string [resource directory],string [file .extension]);
使用 .htaccess 文件
使用 .htaccess 文件将每个请求重定向到Routex库,在那里它可以解析请求的URL并将响应数据发送回客户端。
例如:如果我们想创建一个应用程序,其中[index.php]文件位于public文件夹下,并且我们希望所有请求都应转到[index.php]文件,在这种情况下,我们可以在根目录和public文件夹中创建一个包含以下代码的 .htaccess 文件。
syntax:
# .htaccess file in root directory in which public folder exist
# to block indexing of directory
Options All -Indexes
# to block access for config or security files
<FilesMatch "(\.(bak|config|dist|fla|inc|ini|log|psd|sh|sql|swp)|~)$">
## Apache 2.2
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>
# to redirect all request in public folder
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule (.*) public/$1 [L]
# .htaccess file in public directory where index.php file exist
# to redirect all request to index file
# here you can redirect to any other files if you want
<IfModule mod_rewrite.c>
RewriteEngine On
# Removes index.php from ExpressionEngine URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
</IfModule>
有关更多信息,请访问.htaccess
任何疑问
如有任何疑问,请通过以下电子邮件联系我们:(texnder.components@gmail.com)
文档
有关所有texnder API的文档可在此处找到
许可
aditex是开源的PHP库,许可协议为MIT许可。