I am ubed khan php developer have an 5years plus experience in web development lives in Nagpur India. I have knowledge about phonegap, cakephp ,mysql , jquery, javascript, ajax, html5, and css.
Execute Following query if you created database in during installation
CREATETABLEusers(
idINT(11)NOTNULLAUTO_INCREMENTPRIMARYKEY,
usernameVARCHAR(255)NOTNULLUNIQUE,
passwordCHAR(40)NOTNULL,
group_idINT(11)NOTNULL,
createdDATETIME,
modifiedDATETIME
);
CREATETABLEgroups(
idINT(11)NOTNULLAUTO_INCREMENTPRIMARYKEY,
nameVARCHAR(100)NOTNULL,
createdDATETIME,
modifiedDATETIME
);
CREATETABLEposts(
idINT(11)NOTNULLAUTO_INCREMENTPRIMARYKEY,
user_idINT(11)NOTNULL,
titleVARCHAR(255)NOTNULL,
bodyTEXT,
createdDATETIME,
modifiedDATETIME
);
CREATETABLEwidgets(
idINT(11)NOTNULLAUTO_INCREMENTPRIMARYKEY,
nameVARCHAR(100)NOTNULL,
part_noVARCHAR(12),
quantityINT(11)
);
These are the tables we will be using to build the rest of our application. Once we have the table structure in the database we can start cooking. Use Code Generation with Bake to quickly create your models, controllers, and views.
To bake you just need to follow this video, in video we only baked Group model so repeat same step for User, Post and Widget model. This will have generated the 4 controllers, models and your views for you.
Video
Our third point would be completed here.
Now we are going to set permission to users on the basis of their Group. Which is our last 4th point.
Open app/Controller/UsersController.php and paste following function in that
Now Run application http://localhost/acl/groups/add
Add Following Groups
·administrators
·managers
·users
Then Add users for each
group,
http://localhost/acl/users/add
Note: acl is my project name so do change if your project name is different.
Creating ACOs (Access Control Objects)
Now that we have our users and groups (aros), we can begin inputting our existing controllers into the Acl and setting permissions for our groups and users, as well as enabling login / logout.
Our ARO are automatically creating themselves when new users and groups are created. What about a way to auto-generate ACOs from our controllers and their actions? Well unfortunately there is no magic way in CakePHP’s core to accomplish this. The core classes offer a few ways to manually create ACO’s though. You can create ACO objects from the Acl shell OR by Query. Creating Acos from the shell looks like below OR execute below query
As mentioned before, there is no pre-built way to input all of our controllers and actions into the Acl. However, we all hate doing repetitive things like typing in what could be hundreds of actions in a large application.
After execution
remove this line $this->Auth->allow(); from beforeFilter function and also
remove initDB function from usersController.
Also remove this line $this->Auth->allow(); from beforeFilter function groupsController.
We now have set up some basic access rules. We’ve allowed administrators to everything. Managers can access everything in posts and widgets. While users can only access add and edit in posts & widgets.
You may have noticed that I deliberately left out index and view from my Acl permissions. We are going to make view and index public actions in PostsController and WidgetsController. This allows non-authorized users to view these pages, making them public pages.
So add below beforeFilter function in /app/Controller/PostsController.php and /app/Controller/WidgetsController.php
publicfunctionbeforeFilter(){
parent::beforeFilter();
$this->Auth->allow('index','view');
}
InAppController::beforeFilter()add the following line
$this->Auth->allow('display');
This makes the ‘display’ action public. This will keep our PagesController::display() public. This is important as often the default routing has this action as the home page for your application.
Replace Login and logout
function in /app/Controller/UsersController.php with below Login and logout function.