简体   繁体   English

Angularjs和PHP用于CRUD操作

[英]Angularjs and PHP for CRUD operations

I have tried to look for tutorials on this but nothing simple and to the point... 我试图寻找有关此的教程,但并没有简单到重点...

Could anyone give me an example or link me to a tutorial on how to post data with angularjs to a php page? 谁能给我一个例子或将我链接到有关如何使用angularjs将数据发布到php页面的教程?

And also with angularjs call a php file to get data in order to display a list of lets say a phonebook. 并且还可以使用angularjs调用php文件来获取数据,以便显示电话簿列表。

How can this be done with angularjs? 如何用angularjs完成? I can do all this with php but i want to know how to do it with Angularjs to visualize and call php files and those PHP files would read/write on the db. 我可以用php完成所有这些操作,但是我想知道如何使用Angularjs来可视化和调用php文件,而那些PHP文件将在数据库上读/写。

I want to use plain php(no php frameworks for now). 我想使用普通的php(目前没有php框架)。

Thanks 谢谢

You can do it making in PHP a couple of RESTfull services for the CRUD operation, for this you can use a Framework like Slim . 您可以通过在PHP中为CRUD操作提供几个RESTfull服务来实现,为此您可以使用Slim之类的框架。

Then in AngularJs you can make a service like this for access the data: 然后,在AngularJs中,您可以提供如下服务来访问数据:

app.factory('phoneService', ['$resource',
    function ($resource) {
        return $resource('../app/phone/:id',{id : '@id'},
            { 'findOne': { method: 'GET', params : {id : '@id'}}, isArray:false },
            { 'delete' : { method: 'DELETE', params : {id : '@id'}}, isArray: false },
            { 'save' : {method: 'POST', params : {id : '@id'}}, isArray: false }
        );
    }
]);

After a long search, I've found a simple and best guide for AngularJS beginners. 经过长时间的搜索,我为AngularJS初学者找到了一个简单而最佳的指南。 This example AngularJS application contain the following functionalities. 此示例AngularJS应用程序包含以下功能。

  • Fetch data from the database using PHP & MySQL, and display data using AngularJS. 使用PHP和MySQL从数据库中获取数据,并使用AngularJS显示数据。
  • Add data to the database using AngularJS, PHP, and MySQL. 使用AngularJS,PHP和MySQL将数据添加到数据库。
  • Edit and update data using AngularJS, PHP, and MySQL. 使用AngularJS,PHP和MySQL编辑和更新数据。 Delete user from the database using AngularJS, PHP, and MySQL. 使用AngularJS,PHP和MySQL从数据库中删除用户。

If you are looking for a simple AngularJS application with step-by-step guide, must check this tutorial - AngularJS CRUD Operations with PHP and MySQL 如果您正在寻找带有分步指南的简单AngularJS应用程序,则必须查看本教程- 使用PHP和MySQL进行AngularJS CRUD操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM