如何在Nette框架中使用标准的、普通的非漂亮的url路由?

问题描述 投票:0回答:2

我想在框架 Nette 中使用标准的,而不是漂亮的、漂亮的、干净的、整洁的 url 路由,因为这样它依赖于 apache httpd mod_rewrite 模块,而我没有可用的模块,而漂亮的 url 是默认路由Nette,如何实现它,这样就不需要使用 mod_rewrite 或 nginx 进行此类 url 转换。

php apache frameworks url-routing nette
2个回答
1
投票

在 Nette 中,通过使用简单的路由器类,可以不使用用户友好的漂亮('hezky' - 原始翻译 - )url, 要么

  • 配置 config.neon 中的更新方法,例如

    services: - Nette\Application\Routers\SimpleRouter('Homepage:default') 
    而不是例如。一个配置项自定义自己的路由器工厂路由器:App\RouterFactory::createRouter

  • 或更旧的 bootstrap.php 方式过去是通过自动检测

// Setup router using mod_rewrite detection
if (function_exists('apache_get_modules') && in_array('mod_rewrite', apache_get_modules(), true)) {
    $router = $container->getByType(Nette\Application\IRouter::class);
    $router[] = new Route('index.php', 'User:default', Route::ONE_WAY);
    $router[] = new Route('<presenter>/<action>[/<id>]', 'User:default');

} else {
    $container->addService('router', new SimpleRouter('User:default'));
}

之后的网址可以通过这种格式访问

?presenter=nameOfPresenter&action=nameOfAction
,之前没有它,可以通过
/presenter/action
访问。

来源: https://doc.nette.org/en/application/routing#toc-simplerouter

类似于以前在 Yii 框架中通过配置设置完成的操作

'enablePrettyUrl' => true,
https://github.com/samdark/yii2-cookbook/blob/master/book/enable-pretty-urls.md#url-manager-configuration


0
投票

你可以使用这个不漂亮的路由器

然后在没有 mod_rewrite 的情况下使用它,并将所有请求发送到单个 PHP 文件。

© www.soinside.com 2019 - 2024. All rights reserved.