Modular Application Management in PHP.
Ok so a certain somebody has been asking me how to go about structuring an application that contains many applications (i.e. a content management system for a web site.) I'm going to breifly explain how I do it from a programming perspecitve. Keep in mind:
- This short blurb is going to be done in php / mysql.
- I'm no going to go into much detail outside the overall general concepts.
- I'm assuming you have a general idea of what I'm talking about. Otherwise this is just going to be a bunch of jibba-jabba.
Let's start by addressing what we need to know. As far as each application is concerned we need to know the name of the application, the type or category the application will be classified, and an optional description of the application and what it does. This information can all be summed up in one table called apps. The table contains an id, name field, category id (we do not store the actual category name itself here), desription
The second table acts as a directory of categories. All we keep here is an id, category name, category description. The description is optional additional information about the category.
This figure illustrates the table structures:

So with these two tables it's easy to see you can just grab what you need. For instance to create the main menu of applications you would just query "SELECT cat_id, category FROM categories". Likewise if you wanted to make a submenu displaying alll of the applications in certain category you would just run "SELECT app_id, app FROM apps WHERE category_id=X". You would replace 'X' with the id of the given category.
Advanced!
Handling permissions to applications. You probably saw I included a third table in the figure. Let's say you have a simple authentication system already in place. In that case we would already have the users id on hand. The permissions table simply stores the user id and the application id along with a boolean value. If this value is not equal to 1 we ignore the application becuase the user isn't allowed to see it. An example of a query that would grab all of the information neededwould look like this:
"SELECT
a.app,
a.app_id,
c.category,
c.category_id
FROM
apps a,
categories c,
perms p
WHERE
p.app_id=a.app_id AND
p.access=1 AND
p.user_id=$user_id AND
c.category_id=a.category_id
ORDER BY
c.category_name asc
a.app,
a.app_id,
c.category,
c.category_id
FROM
apps a,
categories c,
perms p
WHERE
p.app_id=a.app_id AND
p.access=1 AND
p.user_id=$user_id AND
c.category_id=a.category_id
ORDER BY
c.category_name asc
This query should give you all of the data you need to build a main menu and sub menus containing applications the user has access to. This method is full proof becuase if the user has access to zero applications in category three then the user would not even know about category three if we built menus off the data from this query. One thing worth mentioning, it works best to sort y the category name or id in your query, this is becuase in your for loop you can detect when the category name / id changes with an embedded if statement and take the necessary actions.
In the end this is a really open ended article but I hope it gives you an essential idea of how to go about structuring the data for an application management system.


2 Comments:
Found a lot of useful info on your site about Content Management System - thank you. Haven't finished reading it yet but have bookmarked it so I don't lose it. I've just started a Content Management System blog myself if you'd like to stop by
Found a lot of useful info on your site about Content Management System - thank you. Haven't finished reading it yet but have bookmarked it so I don't lose it. I've just started a Content Management System blog myself if you'd like to stop by
Post a Comment
<< Home