【发布时间】:2015-03-06 12:44:59
【问题描述】:
假设有一个基于 Web 的 PHP 项目,它使用一个独立的框架,并且还包含一个带有 Laravel 4.2 的文件夹:
project/
laravel/ (Laravel install)
app/
routes.php
public/
index.php
index.php
test.php
.htaccess
.htaccess 文件将每个查询重写为独立框架的 index.php,除非请求了 PHP 脚本(例如,project/test.php)。
在这种情况下,test.php 包含 require laravel/public/index.php 以包含 Laravel 的 index.php 脚本。访问它的 URI 是 http://example.com/test.php。
如何使用Laravel's routing 来了解这个脚本?我试过这个:
Route::get('/test.php', function()
{
echo 'success';exit;
});
但这不起作用(我已经尝试过 test.php 并且只是 test)。转储Route::getCurrentRoute() 输出:
object(Illuminate\Routing\Route)[126] protected 'uri' => string '/' (length=1) ... protected 'compiled' => object(Symfony\Component\Routing\CompiledRoute)[135] ... private 'staticPrefix' => string '/' (length=1) ...
是否可以访问 http://example.com/test.php 并让 Laravel 的路由看到它,就像请求了 /test 或 /test.php 一样,而不需要更改独立框架的 .htaccess 文件? p>
【问题讨论】:
-
我不明白您需要什么。你想通过 Laravel 提供 /test.php URL,即使它是服务器上的物理 .php 文件?那是行不通的。 Laravel 的重写规则明确地使物理文件优先于内部路由。反过来做:将其移动到非公共路径中,然后将其设置为正常的 Laravel 路由并需要来自外部应用程序的资源。
-
嗯,基本上,我想使用脚本 test.php 作为控制器的入口点。我想在 Laravel 中编写一个路由来将路由 /test.php 连接到控制器。
-
你为什么要这么做?你在 text.php 里面做什么?
-
因为我想了解是否可以使用 Laravel 的路由系统,可以在不接触其源代码的情况下以这种方式工作。基本上我不需要在 test.php 中做任何事情,只需要包括 Laravel 的 index.php。
-
你可以实现你的自定义路由类:github.com/pixeloution/laravel-custom-router
标签: php url laravel laravel-4 routing