如何在Laravel 5中设置基本路径 [英] How to set the base path in Laravel 5

查看:67
本文介绍了如何在Laravel 5中设置基本路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将 Laravel的公用文件夹移到了根文件夹,然后将 Laravel 移到了自己的文件夹.因此,我可以在共享主机上使用Laravel.看起来像这样:

  2015/08/04 18:13< DIR>.2015/08/04 18:13< DIR>..2015/08/01 17:50 896 .htaccess2015/07/29 17:39 0 favicon.ico2015/07/29 17:39 1,844 index.php2015/08/04 17:19< DIR>拉拉韦尔2015/08/04 17:20< DIR>上市2015/08/01 17:46 1,165 README.md2015/08/01 16:18 34 robots.txt2015/08/04 17:20< DIR>静止的 

例如,我使用的是 public_path(),我得到了:

/htdocs/laravel/public

但是我需要的是这个

/htdocs/public

我已经检查了/config/中的配置文件,但与此无关.

请告诉我如何解决.

(我的laravel版本是 5.0.33 )


PS:我试过这种方法:共享主机上的Laravel 5-错误的public_path()

我在 AppServiceProvider

中覆盖了 public_path()

  $ this-> app-> bind('path.public',function(){返回base_path().'/';}); 

但是什么都没有改变.

解决方案

您可以通过将公用文件夹添加到通常在/public文件夹中找到的index.php文件中来正确绑定公用文件夹

 //设置此目录的公共路径$ app-> bind('path.public',function(){返回__DIR__;}); 

您可能要在此之后清除缓存,因为之前可能已缓存路径.如果您没有ssh访问 bootstrap/cache/config.php

上的服务器,则可以手动找到和删除缓存的配置.

I moved Laravel's public folder to the root folder, and I moved Laravel to its own folder. So I can use Laravel on a shared hosting. It looks like this:

2015/08/04  18:13    <DIR>          .
2015/08/04  18:13    <DIR>          ..
2015/08/01  17:50               896 .htaccess
2015/07/29  17:39                 0 favicon.ico
2015/07/29  17:39             1,844 index.php
2015/08/04  17:19    <DIR>          laravel
2015/08/04  17:20    <DIR>          public
2015/08/01  17:46             1,165 README.md
2015/08/01  16:18                34 robots.txt
2015/08/04  17:20    <DIR>          static

For example, I'm using public_path() and I get this:

/htdocs/laravel/public

but what I need is this:

/htdocs/public

I've checked config files in /config/ but there is nothing about it.

Please tell me how to fix it. thx

(My laravel version is 5.0.33)


PS: I've tried this method: Laravel 5 on shared hosting - wrong public_path()

I overwrited public_path() in AppServiceProvider

$this->app->bind('path.public', function() {
    return base_path() . '/';
});

But nothing changed.

解决方案

you can bind the public folder correctly by adding this to the index.php file in usually found in your /public folder

// set the public path to this directory
$app->bind('path.public', function() {
    return __DIR__;
});

You may want to clear your cache after this as the paths may have been cached before. The cached config can be located and deleted manually if you don't have ssh access to the server at bootstrap/cache/config.php

这篇关于如何在Laravel 5中设置基本路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆