This tutorial will teach you how to create a CRUD Application using AngularJS,PHP,MySQL and Slim framework.
You can find the source code of this article here
AngularJS is a Java Script framework for dynamic web apps.It lets you extend HTML tags.
Slim is a PHP micro framework which we are going to use for create REST service in php.
Below you can find file structure of the Application.
- js - This folder include all the JavaScript files we use here.
- api - This folder will contain Slim framework.
- pages - This folder contains all the front end pages.
well let's get started with Installing Slim framework inside api folder . Follow the link, If you have any doubts over how to installing it. It's fairly easy process and I am not going write it in detail here.
After installing Slim you'll get a folder call Slim inside api folder.we'll leave it there for the current been.
Next create the index.html file and put below code segment inside it.
Well lets go through this code. We load AngularJS to our app and remember we have to load the angular-route.js too.I will tell you why later in this tutorial. Optionally I load bootstrap style sheet to have to have some sort of user friendly front end
<body ng-app="Application">
You can say this as a starting point of a Angular Application. ng-app directive responsible for auto-bootstrap angular application.
<div ng-view></div>This directive is simply responsible for View of the Application.
Now inside JS folder create app.js file.
Here we have our 'Application' module.
In First line we declare our module.In this case it's Application. Second argument is a array. It consist of dependencies for the module.Here we need 'ng-Route' since it is the module that responsible for provide routing and deeplinking services and directives for angular apps.
Rest of the code is for set routs for the App.$routeProvider use for configuring routes.I recommend you to go through above link to get a better understand about $routeProvider. Actually this is where we need above discussed 'ng-Route' module to be installed as a dependency for $routeProvider.
Lets we move on to create our first Controller.
This is the controller for get the list of customer details.
AngularJs application are controlled by Controllers. 'CustomerListControler' is a JavaScript function and $scope is the application object. Which means it owns the application variable and objects.
$http use to communicate with web servers.
$http.get is the function use to read the server data and those data will store in property call customers.
What we have here is Controller for add a new customer.
One of new thing we come across here is $location. $location service parses the URL in the browser address bar and makes the URL available to your application.Changes to the URL in the address bar are reflected into $location service & changes to $location are reflected into the browser address bar.
Then we move onto create 'CustomerEditController', The Controller that will responsible for handle Edit and Delete.
Hm..looks like we don't have anything new to discuss here. So we'll move on to create database handling section.
Go to index.php file inside Slim folder.
In first two lines we call & create instance of Slim. Then comes the interesting part of Slim's route handling.As you can see it's really easy to understand .That is the one of main reason we use Slim framework here.If you want to know more about Slim routing follow this Then we'll create actual database connection & database handling.
Now we almost end.All you have to do is create frond end pages for add,update and detailed list of customers.
Go to pages folder and create list.html,new.html and edit.html files
Well..It's done guys.Now we have your own little AngularJS application whichcapable of doing CRUD operation.I hope you enjoy the tutorial.
Happy coding.
You can find the source code of this article here
- 11:35:00 AM
- 29 Comments


