Laravel和AngularJS意见结构 [英] Laravel and AngularJS views structure

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

问题描述

最近,我开始到Digg到angularjs,并会帮助我很多与我的新项目,但即时通讯stucked与视图结构部分。

I recently started to digg in to angularjs, and would help me a lot with my new project, but im stucked with the view structure part.

所以,我真的不明白是什么,如何建立起来。
它是好,如果我创建HTML角谐音,而不是创造laravel意见,所以laravel只会处理数据库instert fecth编辑删除和角部分意见将处理结果表明,和形式。

So what i dont really understand is, how to build it up. Is it okay if i create html angular partials and not creating laravel views, so laravel would only handle the database instert fecth edit delete, and the angular partial views would handle the result show, and forms.

所以,我buold起来是这样的。
我的资产文件夹

So my buold up would look like this. My assets folder

/css
/img
/js
 /lib
 /partials
         /home
             index.html
         /users
             users.html
             details.html

和创建宁静控制器对他们有什么handlets上述

And creating restful controllers for them what handlets listed above

或者,如果有人能证明我的这个基本的exaple,只是在控制器和视图部分,如何建立与显示结果的页面singple,一个由ID掠我真的很感激。

Or if someone could show my a basic exaple about this, just the controller and view part, how to build up a singple page with showing result, and one with grabing by id i would really be grateful.

感谢您

推荐答案

在开始Laravel&安培; AngularJS项目,你是负责后端和前端的。基本上,你有3个选择。

When starting a Laravel & AngularJS project you are in charge of the backend and frontend. Basically you have 3 options.


  1. 保存在同一文件夹整个应用程序,并在公共文件夹中的angularjs东西。

  2. 保持在laravel视图文件夹相同的文件夹和AngularJS享有整个应用程序。

  3. 您分离后端和前端完全。

第一&放大器;第二个选项是最简单的,它的确定,如果你有一个小型/中型应用。在这种情况下,只是让所有的AngularJS文件在公共文件夹,或如果您选择将它们与laravel意见混合刚落.blade扩展名(或更改laravel刀片/ angularjs模板语法)

The first & second option are the simplest, and its OK if you have a small/medium sized application. In this case just keep all the AngularJS files in the public folder, or if you choose to mix them with laravel views just drop the .blade extension (or change the laravel blade/angularjs template syntax)

我看到它的最好保持后端尽可能宁静做SPA的应用程序时,该点是逻辑推到浏览器,这意味着你的应用程序可以成为一个烂摊子,如果你用JS混合PHP的太多了。

I see its best to keep the backend as restful as possible when doing a SPA app, the point is to push the logic to the browser, this means your app can become a mess if you mix php with js too much.

的文件夹结构是完全取决于你,这不要紧,你选择什么样的选项。但是,一个良好的开端是应用分离你变成一个逻辑部分。

The folder structure is totally up to you, and it does not matter what option you choose. But a good start is separating you app into a logical parts.

/app
    application.js
    /partials
         user.html
         login.html
         etc.html
    /vendor
         Angular.js
         Lodash.js
         Etc.js
    /controllers
         User.js
         Etc.js
    /directives
         Charts.js
         Etc.js
    /filters
         Custom.js
         Etc.js
    /services
         Backend.js
         Etc.js

您还可以查看一个良好的angularjs风格指南。

You can also check this for a good angularjs styleguide.

以上是一个基本的文件夹结构,只是定制它正如你看到的最好的。如果你有一个小的应用程序,你可以删除该文件夹,只是有一个 controllers.js directives.js和services.js(等),并保持所有你的JavaScript在同一文件。这完全取决于你。当应用程序的增长分开,始终重构。

The above is a basic folder structure, just customize it as you see best. If you have a small app, you could drop the folders and just have a controllers.js directives.js and services.js (etc)and keep all your javascript in the same file. This is totally up to you. Separate when the application grows, and always refactor.

如果您选择第三个选项则必须自定义后端一点。这可能是最难的选择,但它也给了你很大的灵活性。基本上,你可以放下所有laravel一起,并在建立的Node.js后端,或者使用laravel作为写在Ember.js未做在code的任何变化另一个SPA应用后端。注意:如果你选择这个选项,你不能使用一些laravel东西,比如刀片模板。您还可以设置为CORS您laravel应用程序,并注意,可以有一些更多的编码,当涉及到安全,像CSRF令牌和等。

If you choose the third option you will have to customize the backend a bit. This might be the hardest option, but it also gives you great flexibility. Basically you could drop laravel all together, and build the backend in node.js, or use laravel as a backend for another SPA app written in Ember.js without making any changes in the code. Note if you are choosing this option you cannot make use of some laravel stuff, like the blade templating. You will also have to setup your laravel app for CORS, and note, there can be some more coding when it comes to security, like CSRF tokens and such.

在将生产与应用程式,你可以使用一个构建工具来最小和放大器; CONCAT你的前端应用到一个文件中。结帐 NG-分钟以缩小。

When going to production with you app you can use a build tool to min & concat you frontend app into one file. Checkout ng-min for minification.

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

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