Yii2 + AngularJS 在单个应用程序中 - 怎么样?
Yii2 + AngularJS in a single application - how?
我对这两个方面都有经验 Yii 2 and AngularJS,但是是分开的。我有两个问题:
是否可以在 Yii 2 的视图中使用 AngularJS?我问的是 possible 而不是 feasible,因为我认为问题可能已经到了路由
此外,同时使用 Yii 2 和 AngularJS 是否足够公平(为了性能)? (两者都是 MVC,因此适用于模块化、可管理的代码。)
找了半天,没找到合适的资源。什么解释!
YES,可以在Yii 2查看后使用AngularJS实施不同的生根方法。这里是 a tutorial to start with.
但是 NO,我不建议这样做(虽然 Yii 2 和 AngularJS 是很好的框架,原生支持 REST). So the proper way is to use AngularJS to build your frontend and use Yii 2 just to provide a server API。这是一个很好的结构:
Structure by @AlekseiAkireikin from
project/
backend/ // Yii 2 application
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/
...
Yii RESTful API framework will provide a clean API which can communicate with your built-in AngularJS application or maybe a future mobile app or even providing resources and/or services to other websites or software. If you care about performance then go with both and use REST. A well-structured RESTful application is great to easily build a good caching system with a flexible strategy behind. You can even host your backend and database on a server (like Amazon EC2) providing only JSON (and/or XML) data for minimum bandwidth use, and having your frontend stored on an optimized CDN(如 Amazon S3 或其他 CDN 提供商)具有更低的成本和更快的答案。
我对这两个方面都有经验 Yii 2 and AngularJS,但是是分开的。我有两个问题:
是否可以在 Yii 2 的视图中使用 AngularJS?我问的是 possible 而不是 feasible,因为我认为问题可能已经到了路由
此外,同时使用 Yii 2 和 AngularJS 是否足够公平(为了性能)? (两者都是 MVC,因此适用于模块化、可管理的代码。)
找了半天,没找到合适的资源。什么解释!
YES,可以在Yii 2查看后使用AngularJS实施不同的生根方法。这里是 a tutorial to start with.
但是 NO,我不建议这样做(虽然 Yii 2 和 AngularJS 是很好的框架,原生支持 REST). So the proper way is to use AngularJS to build your frontend and use Yii 2 just to provide a server API。这是一个很好的结构:
Structure by @AlekseiAkireikin from
project/
backend/ // Yii 2 application
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/
...
Yii RESTful API framework will provide a clean API which can communicate with your built-in AngularJS application or maybe a future mobile app or even providing resources and/or services to other websites or software. If you care about performance then go with both and use REST. A well-structured RESTful application is great to easily build a good caching system with a flexible strategy behind. You can even host your backend and database on a server (like Amazon EC2) providing only JSON (and/or XML) data for minimum bandwidth use, and having your frontend stored on an optimized CDN(如 Amazon S3 或其他 CDN 提供商)具有更低的成本和更快的答案。