Laravel:如何路由到公共文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15836443/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel: How to Route to Public file
提问by Avisek Chakraborty
In Laravel, is it possibleto redirect to a public/testFile.php
, through routing?
在 Laravel 中,是否可以public/testFile.php
通过路由重定向到, ?
In the application/routes.php
,
在application/routes.php
,
Route::get('/', function()
{
//'How to point to public/testFile.php'
});
Have an existing Project, But want to do Only the NEW MODULES in Laravel. So copied the Existing project under Public/
有一个现有的项目,但只想在 Laravel 中做新的模块。所以复制了Public/下的Existing project
采纳答案by Sébastien Renauld
You are completely defeating the purpose of the framework by doing this, but if you really want to...
你这样做完全违背了框架的目的,但如果你真的想......
Route::get("/", function() {
ob_start();
require(path("public")."testFile.php");
return ob_get_clean();
});
This will return the stdout output of the file. If instead you have a return value already in the script, knock out ob_start
and the return
call.
这将返回文件的 stdout 输出。相反,如果脚本中已有返回值,请敲除ob_start
并return
调用。
Redirects are done as follows:
重定向按如下方式完成:
Route::get("/", function() { return Redirect::to("testFile.php"); });
回答by Muhammad Usman
Route::get('/', function()
{
include public_path().'testFile.php';
});
If you want to Redirectthen use return Redirect::to('testFile.php')
如果你想重定向然后使用return Redirect::to('testFile.php')
But I don't get why you want to do this weirdthing.
但我不明白你为什么要做这种奇怪的事情。
I think you are using Laravel 3 (as you mentioned application/...
), there public_path()
is path('public')
.
我认为你正在使用Laravel 3(如你所提到的application/...
),还有public_path()
就是path('public')
。