假设有一个基于 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 文件进行更改?
最佳答案
你不是被迫使用 Laravel 路由,你可以用纯 PHP 绕过它:
if($_SERVER['REQUEST_URI'] === '/test.php')
{
exit('success');
}
但在您的情况下,您可能应该使用 .htaccess 将所有请求重定向到 Laravel,并在 Laravel 不处理页面时回退到根目录 index.php:
App::missing(function($exception)
{
include('../../index.php');
exit;
});
关于php - 将 Laravel 包含到自定义 PHP 脚本中并路由到 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27839508/