codedgr/router

将 URL 变量路由到您的项目

1.0.0 2018-06-06 15:39 UTC

This package is auto-updated.

Last update: 2024-09-14 20:20:15 UTC


README

将 URL 变量路由到您的项目

安装

将以下内容添加到您的 .htaccess 文件中,以便将所有内容重定向到 index.php 文件。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ index.php

##构建 URL 定义 PARSE_URL 使用您的域名

define('PARSE_URL','https://www.example.gr')

使用 url() 函数,并添加您想要的属性。

$url = Parse::url('class', 'method', ['var'=>'foo','foo'=>'boo']);

上面的例子将输出

https://www.example.gr/class/method/var=foo&foo=boo

##从 URL 解析变量 将 URL 传递给 Parse 对象,并使用 get 方法获取变量数组。

$array = (new Parse($url))->get();

如果我们使用之前的 URL,这个例子将输出

Array
(
    [0] => class
    [1] => method
    [2] => Array
        (
            [var] => foo
            [foo] => boo
        )

)

您也可以传递您想要的键

$var = (new Parse($url))->get(1);

如果我们使用之前的 URL,这个例子将输出一个字符串 methodfalse 如果没有值