更改Laravel目录结构 [英] Change laravel directory structure

查看:71
本文介绍了更改Laravel目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

atm我开始开发一个大型应用程序,而laravel的当前结构恰恰与我的想法不符.控制器,模型和视图都放在单独的文件夹中,只是捆在一起,装满它们时,事情可能会变得一团糟.

atm i'm beginning to develop a big application and the current structure of laravel just doesn't fit what i had in thought. The controllers, models and views are all in seperate folders just bunched up and things could get messy when there's loads of them.

所以我希望可以更改laravel加载其控制器视图和模型的默认方式.我的方法是这样的:

So I was hoping I could change the default way laravel loads it's controllers views and models. My approach would be something like this:

-App
--Content
---Login
----Controller
----Model
----View
----Js
---Home
----Controller
----Model
----View
----Js
--BaseContent
---BaseLayout
---BaseController
---BaseJS

因此,当路由归位时,控制器模型视图和javascript都捆绑在一个文件夹中,而不是全部都放在一个控制器目录,模型目录,视图目录等中.

So when the route is home the controller model view and javascript all get bundled in a folder instead of having all of it in one controller directory, model directory, view directory etc.

所以我的问题是有人知道我该如何改变laravel加载方式的依赖方式吗?我有点希望找到似乎找不到的配置文件.

So my question is does someone know how I could change the way laravel load's it's dependency's? I'm kinda hoping for a configuration file I just can't seem to find.

推荐答案

我了解您的想法.您想按功能分组.

I understand your thoughts. You want to group by feature.

有可能.您所需要的只是符合PSR-4的名称空间.在composer.json中,您可以链接/指定名称空间和路径,例如,您的控制器中具有以下行:

It's possible. All you need are namespaces conform PSR-4. In composer.json you can link/specify the namespaces and paths, for example, you have in your controller this line:

namespace App\Http\Controllers;

composer.json中,请参见autoload中的以下片段:

In composer.json see the following fragment in autoload:

"psr-4": {
    "App\\": "app/"
}

名称空间App引用目录app,所有具有以App\开头的名称空间的类都将被自动加载.因此,更改目录结构很简单.

The namespace App refers to the directory app, and all classes with the namespace beginning with App\ will be autoloaded. So it's simple for your to change the directory structure.

这篇关于更改Laravel目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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