[英]In Laravel 5, how can I move the controllers out of the 'app' folder
I am placing all the classes codes in a separate folder. 我将所有类代码放在单独的文件夹中。 I have created a folder 'src' alongside the folder 'app'.
我在文件夹“ app”旁边创建了一个文件夹“ src”。 Within this 'src' folder will be 'Models', 'Views' and 'Controllers' folder and 'routes.php' file too.
在此“ src”文件夹中还将包含“模型”,“视图”和“控制器”文件夹以及“ routes.php”文件。 So the scructure will be as follows.
因此,结构将如下。
I have moved the routes.php and views to src by changing the routing path in 'app\\Providers\\RouteServiceProvider.php' and view path in 'config/view.php'. 我已经通过更改“ app \\ Providers \\ RouteServiceProvider.php”中的路由路径和“ config / view.php”中的视图路径,将routes.php和视图移至src。 Please correct me if I did anything wrong here.
如果我在这里做错了什么,请纠正我。
My question is - how can I move controllers, models, views and route.php from app to src? 我的问题是-如何将控制器,模型,视图和route.php从应用程序移动到src?
I want to do this because I want to palce all the user written codes in one place. 我想这样做是因为我想将所有用户编写的代码放在一个地方。 I don't want to move the app/Http/Controllers/Controller.php.
我不想移动app / Http / Controllers / Controller.php。 I just want to move the user created controllers.
我只想移动用户创建的控制器。
I want to achive this without braking anything at other places. 我想实现这一目标而不在其他地方刹车。
You can move your code there, you'll just need to tell autoloader where to find those classes. 您可以将代码移到那里,只需要告诉autoloader在哪里可以找到那些类。 You'll need to update autoload section in your composer.json .
您需要在composer.json中更新autoload部分。
What namespace are your controllers in? 您的控制器位于哪个名称空间? It will impact what you need to put there.
这将影响您需要放置的内容。 If you store them in \\App\\Http\\Controllers , you'll need to add the following there:
如果将它们存储在\\ App \\ Http \\ Controllers中 ,则需要在其中添加以下内容:
"autoload": {
"classmap": [],
"psr-4": {
"App\\Http\\Controllers\\": "src/Controllers/",
}
},
This will tell autoloader that the root directory for App\\Http\\Controllers namespace is src/Controllers/ folder. 这将告诉自动加载器, App \\ Http \\ Controllers命名空间的根目录是src / Controllers /文件夹。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.