Yii 2:AngularJS 的目录结构?
我的 Yii 2 应用程序的目录结构应该是什么?使用 Yii 2 视图真的有意义吗,还是我必须创建一个 AngularJS 应用程序目录并将 Yii 应用程序放在它的一个文件夹中?
What should the directory structure of my Yii 2 application be? Does it really makes sense to use Yii 2 views or do I have to create an AngularJS application directory and put the Yii application in one of its folders?
解释是什么?
推荐答案
我建议您将后端 (Yii 2) 和前端 (AngularJS) 分成两个单独的文件夹.死苍蝇和肉丸应分开食用.Yii 2 只提供服务器 API,而 AngularJS 做所有其他事情.
I recommend you to split your backend (Yii 2) and frontend (AngularJS) in two separate folders. Dead flies and meatballs should be served separately. Yii 2 just provides the server API, while AngularJS does all other things.
project/
backend/ // Yii2 app
web/ // Public visible backend folder
index.php // Entry point
config/
controllers/
models/
...
frontend/
app/ // Your AngularJS application here
css/ // Styles (.less or .css)
img/ // Images
lib/ // Third-party libraries such as jQuery or AngularJS
js/ // .js files (controllers, services, etc.)
partials/ // Templates (.html)
index.html
tests/ // AngularJS tests
node_modules/
...
Web 服务器应该这样配置:
The web server should be configured this way:
http://mycoolsite.com/api/*
请求project/backend/web/
;http://mycoolsite.com/*
请求project/frontend/app/
.
http://mycoolsite.com/api/*
requests toproject/backend/web/
;http://mycoolsite.com/*
requests toproject/frontend/app/
.
如果您使用 Apache 作为网络服务器,mod_alias 可以提供帮助你.
If you use Apache as a web server, mod_alias can help you.
请注意,backend
或 frontend
目录中的文件夹结构可能会有所不同.
Note, that the folder structure inside the backend
or frontend
directory may vary.
- 对于
后端
,这取决于您喜欢哪种模板(基本或高级).在我的示例中,我使用了基本的. - 对于
frontend
,这取决于您的 AngularJS 应用程序组织.在示例中,我使用了 AngularJS 教程应用程序,但对于大型应用程序,最好使用 模块化结构.
- For
backend
it depends on which template you prefer (basic or advanced). In my example I used the basic one. - For
frontend
it depends on your AngularJS application organization. In the example I used the AngularJS Tutorial App, but for huge applications it is better to use a modular structure.
相关文章