2015-02-10 4 views
5

Приложение Laravel работает в частной папке, и мне нужно сообщить Laravel, что общий путь отличается. Сегодня я обновил приложение Laravel с 4.2 до 5.0, и я не могу найти, где мы укажем общий путь since the paths.php file doesn't exist anymore in Laravel 5.0.Укажите другой общедоступный путь

В Laravel 4.2 мы имели /bootstrap/paths.php файл:

/* 
|-------------------------------------------------------------------------- 
| Public Path 
|-------------------------------------------------------------------------- 
| 
| The public path contains the assets for your web application, such as 
| your JavaScript and CSS files, and also contains the primary entry 
| point for web requests into these applications from the outside. 
| 
*/ 

'public' => __DIR__.'/../../../public_html', 

Я не используется со структурой Laravel 5.0 папки все же, любая помощь будет принята с благодарностью.

+1

Вы можете попробовать создать свой собственный класс Helper и переопределить функцию public_path' и переименовать публичного исполнителя в соответствии с вашими предпочтениями. – manix

+0

Можете привести пример? Это решение выглядит немного сложнее, и я всегда думал, что Laravel был создан для каждого типа хостинга, было бы неутешительно, если бы это было не так. – roastedtoast

+0

Лучшим решением является выбранный ответ. Пожалуйста, найдите минутку, чтобы прочитать ее и ее комментарии, и старайтесь не перегружать приложение бесполезными классами. – roastedtoast

ответ

13

То, что сработало для меня безотказно добавлял к public/index.php следующие три строки:

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

Это был дан ответ на Laracast.

+1

В самом начале файла? – Asim

+1

Сразу после '' $ app = require_once __DIR __. '/ ../private/yourappfolder/bootstrap/app.php '; '' Где «yourappfolder» является вашей папкой Laravel и где «private» - это папка, в которой находится папка laravel. Попробуйте удалить «..» или добавить «../ ..» в зависимости от того, где находится ваша общая папка. – roastedtoast

+1

@Rubens Mariuzzo это не работает для меня на L 5.2. –

2

Я думаю, что это может быть сделано по-разному, вот моя.

Создайте новый вспомогательный файл. Вы можете создать его в Services папке:

# app/Services/helper.php 

if (! function_exists('private_path')){ 
    function private_path($path = ''){ 
     return app_path() . 'private/' 
    } 
} 

Хорошее место, чтобы импортировать вспомогательный файл находится в AppServiceProvider, который находится в app/Providers/AppServiceProvider.php. Для этого используйте boot.

public function boot() 
{ 
    include __dir__ . "/../Services/helper.php"; 
} 

Переименовать папку public в private, и, наконец, вы можете назвать свою собственную функцию из любого места, как:

$path = private_path(); 
+0

Вы имели в виду AppServiceProvider вместо AuthServiceProvider? – roastedtoast

+0

yes, AppServiceProvider – manix

+0

Я создал файл helper.php с функцией и добавил включение в функцию загрузки, что мне делать дальше? Что вы имеете в виду под «переименовать папку с публичного на частный»? – roastedtoast

0

Согласно this post, чтобы заменить оригинальный общественный путь, мы должны переопределить приложение пути:

<?php namespace App; 

use Illuminate\Foundation\Application; 

class MyApp extends Application { 

    protected $appPaths = array(); 

    /** 
    * Create a new Illuminate application instance. 
    * 
    * @param array|null $appPaths 
    * @return \MyApp 
    */ 
    public function __construct($appPaths = null) 
    { 
     $this->registerBaseBindings(); 

     $this->registerBaseServiceProviders(); 

     $this->registerCoreContainerAliases(); 

     if (!is_array($appPaths)) { 
      abort(500, '_construct requires paths array'); 
     } 

     if (!isset($appPaths['base'])) { 
      abort(500, '_construct requires base path'); 
     } 

     $this->appPaths = $appPaths; 

     $this->setBasePath($appPaths['base']); 
    } 

    /** 
    * Set the base path for the application. 
    * 
    * @param string $basePath 
    * @return $this 
    */ 
    public function setBasePath($basePath) 
    { 
     $this->basePath = $basePath; 

     $this->bindPathsInContainer(); 

     return $this; 
    } 

    /** 
    * Bind all of the application paths in the container. 
    * 
    * @return void 
    */ 
    protected function bindPathsInContainer() 
    { 
     $this->instance('path', $this->path()); 

     foreach (['base', 'config', 'database', 'lang', 'public', 'storage'] as $path) 
     { 
      $this->instance('path.'.$path, $this->{$path.'Path'}()); 
     } 
    } 

    /** 
    * Get the path to the application "app" directory. 
    * 
    * @return string 
    */ 
    public function path() 
    { 
     return $this->basePath.'/app'; 
    } 

    /** 
    * Get the base path of the Laravel installation. 
    * 
    * @return string 
    */ 
    public function basePath() 
    { 
     return $this->basePath; 
    } 

    /** 
    * Get the path to the application configuration files. 
    * 
    * @return string 
    */ 
    public function configPath() 
    { 
     if (isset($this->appPaths['config'])) { 
      return $this->appPaths['config']; 
     } 
     return $this->basePath.'/config'; 
    } 

    /** 
    * Get the path to the database directory. 
    * 
    * @return string 
    */ 
    public function databasePath() 
    { 
     if (isset($this->appPaths['database'])) { 
      return $this->appPaths['database']; 
     } 
     return $this->basePath.'/database'; 
    } 

    /** 
    * Get the path to the language files. 
    * 
    * @return string 
    */ 
    public function langPath() 
    { 
     if (isset($this->appPaths['lang'])) { 
      return $this->appPaths['lang']; 
     } 
     return $this->basePath.'/resources/lang'; 
    } 

    /** 
    * Get the path to the public/web directory. 
    * 
    * @return string 
    */ 
    public function publicPath() 
    { 
     if (isset($this->appPaths['public'])) { 
      return $this->appPaths['public']; 
     } 
     return $this->basePath.'/public'; 
    } 

    /** 
    * Get the path to the storage directory. 
    * 
    * @return string 
    */ 
    public function storagePath() 
    { 
     if (isset($this->appPaths['storage'])) { 
      return $this->appPaths['storage']; 
     } 
     return $this->basePath.'/storage'; 
    } 
} 

Это кажется странным для меня, и, как уже упоминалось в сообщении, похоже, что мы сделали вернемся к функциям Laravel, я надеюсь, что они изменят его в будущем обновлении.

Смежные вопросы