转换我的网站使用JS角我的、网站、JS

2023-09-13 04:50:54 作者:﹎听、哭泣得声音

所以,最近我一直在看AngularJS,我与许多它pssed真的IM $ P $的功能。我目前的开发在传统的庄园网站(PHP,HTML,CSS,MySQL的,有点的jQuery),我真的想这样,我就采用了棱角分明的网站转换。我想这样做,因为我目前混合PHP与HTML在许多网页,它正成为很难看到presentation,数据和逻辑的谎言(一个角度问题似乎解决得非常好)。我有理由经历了网站开发和编程,但有角没有经验,除了通过在其网站上的教程和一些其他的阅读运行在这里和那里。

So, I've been looking at AngularJS recently and I'm really impressed with many of it's features. I am current developing a site in a traditional manor (php, html, css, mysql, a bit of jQuery) and I would really like to convert the site so that I am using Angular. I want to do this because I am currently mixing PHP with HTML in many of the pages and it is becoming hard to see where presentation, data and logic lies (a problem Angular seems to solve very well). I am reasonably experienced in web development and programming but have no experience with Angular, apart from running through the tutorial on their website and some miscellaneous reading here and there.

角似乎在此刻非常陌生的我,我想知道如果你们中的一些可以帮助我了解如何做某些事情在最恰当的方式。我不指望详细的解释,但任何链接到适当的角度指令/其他SO问题/其他网站将是非常有益的。

Angular seems very alien to me at the moment and I was wondering if some of you could help me understand how to do certain things in the most appropriate way. I do not expect detailed explanations, but any links to appropriate Angular directives / other SO questions / other sites would be very helpful.

我的设计布局十分简单:

The layout of my design is quite simple:

后端:

MySQL数据库,用于存储有关的所有页面的信息[标题,访问级别,路径到文件,等等。] 包含功能 PHP文件启动会话,并与数据库交互例如getPageData(),signInUser(),signOutUser()等。

前端:

的index.php - 主要的模板页面。包括后端PHP文件,以提供其功能的访问。用户请求的页面是一个GET参数,所以一个典型的URL看起来像'domain.com/index.php?page=home(尽管这是由屏蔽的.htaccess看起来像'domain.com/home') 。所有内容页面包含在&LT; D​​IV&GT; 在本页面 index.php - The main template page. Includes the backend PHP files to provide access to their functions. The page the user is requesting is a GET parameter, so a typical URL would look like 'domain.com/index.php?page=home' (although this is masked by .htaccess to look like 'domain.com/home'). All content pages are 'included' in a <div> in this page

据我所知,从根本上,我需要从内容的index.php网页删除所有PHP,而是发出Ajax请求到后端PHP文件应该输出JSON对象其角就可以使用构建DOM的方式我把它编程为。

I understand that fundamentally, I need to remove all the PHP from the content and index.php pages and instead make ajax requests to the backend PHP files which should output JSON objects which Angular can then use to construct the DOM in the way I program it to.

我不明白我应该如何:

获取URL参数发送给getPageData()函数在后台PHP,或得到任何其他的URL参数为此事。 (角似乎使用的URL的哈希一部分,而不是标准的'?')包含在index.php页面内容页面(我应该使用NG-视图或NG-包括哪些内容?)

另外,我能想象它是不是很有效,使多个$ HTTP请求时,页面加载:例如一个到达页数据,一个到达像访问层次,一个用户的数据来获得的下载数据等。会不会每个请求在服务器上启动一个新的线程,并要求该会话启动,登记等常量

Also, I can imagine it is not very efficient to make multiple $http requests when the page is loaded: e.g. one to get page data, one to get the user's data like access-level, one to get downloads data and so on. Won't each request start a new thread on the server and require the session to be started, constants to be registered etc.

我的提问巨大的无限制性道歉,谢谢大家提前这么多的时间

I apologise for the huge open-endedness of the question and thank you all so much in advance for your time

推荐答案

是的,你已经得到了你前面了很多。不过不要担心,我在你的立场曾经和我在很短的时间使其通过(并爱上角)。

Yep you've got a lot ahead of you. But don't worry I was once in your position and I made it through in a short time (and fell in love with Angular).

至于你说你的问题是pretty开放式的,而是关于你的页面和URL参数,我真的建议你看看UI路由器作为替代角度的ngRoute。

As you said your question is pretty open ended, but with regards to your pages and URL parameters, I really recommend you take a look at ui-router as an alternative to Angular's ngRoute.

https://github.com/angular-ui/ui-router

有类似$路径pretty / $ routeProvider一般包含在角(实际上好它依赖于它,它缴费),但确实有点多。它可以让你设置有自己的URL和参数的状态(路由)。他们有一个很好的教程,如果你了解UI路由器,棱角分明的路线会让很多更有意义。

It is pretty similar to the $route/$routeProvider generally included in Angular (well actually it depends on it and expends it) but does a bit more. It allows you to set states(routes) that have their own urls and parameters. They have a nice tutorial and if you understand ui-router, angular's routes will make a lot more sense.

在总结这两个ngRoute和ui.router可以解决您的网址权限/参数的问题。 ui.router允许你做更多,但ngRoute可能是因为它比较稳定角官伞里面。

In conclusion both ngRoute and ui.router can solve your URL permissions/parameter problems. ui.router allows you to do more but ngRoute is probably more stable as it inside Angular's official umbrella.