laravel 5更改app目录以匹配命名空间

时间:2015-03-03 01:27:23

标签: php namespaces directory laravel-5

如果您想重命名您的应用程序文件夹,这只是其中几种方法之一。

  • 1)运行php artisan app:name YourNamespace
  • 2)将您的app文件夹重命名为YourNamespace
  • 3)在您的bootstrap文件夹中创建一个名为application.php
  • 的文件
  • 4)将其粘贴在那里

    class Application extends Illuminate\Foundation\Application {
    
        /**
         * this is the default for the application path
         */
        protected $appBasePath = 'app';
    
        public function __construct($basePath = null)
        {
            $this->registerBaseBindings();
    
            $this->registerBaseServiceProviders();
    
            $this->registerCoreContainerAliases();
    
            if ($basePath) $this->setBasePath($basePath);
        }
    
        public function setAppPath($path) {
            // store the path in the class only
            $this->appBasePath = $path;
    
            // set the path in the container (using this class's path to reset it)
            return app()->__set('path', $this->path());
        }
    
        /**
         * Get the path to the application "app" directory.
         *
         * @return string
         */
         public function path()
        {
            return $this->basePath.DIRECTORY_SEPARATOR.$this->appBasePath;
        }
    
    }
    
  • 5)保存文件并打开app.php

  • 6)并使用以下

    替换您的应用程序引导程序
     // load our local application
     require __DIR__.'/application.php';
    
     // instaniate our application
     $app = new \Application(
        realpath(__DIR__.'/../')
     );
    
     // set the path to match the namespace
     $app->setAppPath('YourNamespace');
    
  • 7)保存你的app.php就是这样,请记住你应该把它添加到你的测试中。

希望这有助于任何想要更改其命名空间并希望它与目录结构匹配的人。

0 个答案:

没有答案