Laravel: How to Route to Public file

偶尔善良 提交于 2019-11-30 02:16:26

问题


In Laravel, is it possible to redirect to a public/testFile.php, through routing?

In the 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/


回答1:


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.

Redirects are done as follows:

Route::get("/", function() { return Redirect::to("testFile.php"); });



回答2:


Route::get('/', function()
{
    include public_path().'testFile.php';
});

If you want to Redirect then use return Redirect::to('testFile.php')

But I don't get why you want to do this weird thing.

I think you are using Laravel 3 (as you mentioned application/...), there public_path() is path('public').



来源:https://stackoverflow.com/questions/15836443/laravel-how-to-route-to-public-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!