Ever since I have started programming with PHP, the most repetitive and unchallenging task I have had to do is to write code for administration control panels. Every project I make needs one, and a good one at that, so that it is easy for my clients to manage their websites, without needing my help (which saves them both time and money), but it gets repetitive.
The problem
Let us say for example that we want to create a small personal website, where the owner can post news articles. I need to write the code for the administration control panel (bearing in mind that the admin needs a login to stop unauthorized access). That implies coding at the very least a login page, logout, and a basic dashboard. Afterwards, it is necessary for me to write code to manage/view/create/edit/delete news articles. So far, it’s simple. Six months later, the owner e-mails me telling me that his website became very popular, and he wants to enable comments on his news articles. He also wants people to sign up for a newsletter and the ability to write newsletters from the administration control panel (and keep a record of the ones that he already sent). Now, the administration panel has to have a page to manage/view/edit/delete comments, and it has to have a page to manage/view/edit/delete users. It also has to have a page to manage/view/create newsletters. Suddenly, that simple administration panel is now a bit more complex. Granted, this is still not a big problem. However, not all websites are that simple. Some websites can have far more tables, and be far more complex than the simple personal website illustrated in this example. Additionally, it consumes a large amount of time, especially on the more complex websites. After countless times of doing this for every project, I decided that I had to write something to generate the administration panel’s code for me.
The solution – Terra Duo Admin
As soon as I had the free time, I started writing a controller class to generate manage/view/create/edit/delete pages on demand, designed to be as simple as possible. My theory was that the simpler it was to implement this on a new or existing project, the more efficient it would be. For that purpose, I started by writing the code that I wanted to have in order to generate the pages, and I came up with the following:
$Admin->setTableConfigs($tableConfigsArray); # This would contain an array describing the table’s name, the table’s fields, along with their validation rules and any other settings necessary to administer a table.
$Admin->Create();
$Admin->Edit($ID);
$Admin->Delete($ID);
$Admin->View($ID);
$Admin->Manage($Page, $RowsPerPage);
I felt that that was the only code that was necessary to write for any administration control panel, on any project. It keeps it as simple as it can possibly be, and it would allow me to spend more time working on the frontend (which is what really matters, since that is what the end-users see). I could go to my CodeIgniter admin controller and dump this code there, to get admin/create, admin/edit, admin/delete, etc working, and have myself a nice administration control panel. I knew about Symphony’s Admin Generator, but the fact that it was only for Symphony was one of the reasons why I did not want to use it. The other was simply that I wanted to abstract away as much as possible, and leave it with the least amount of configuration necessary. I also didn’t want it to generate physical code files, because I would then have to deal with updating them whenever I updated the database structure. I wanted something that would just work, based on the table configurations array I gave it, so that if for example, I was in the manage users section, I would give it the configurations for the users table, and if I was in the manage news posts section, I would give the configurations for the news table, and so on. After that, it would generate the requested page, for the given table. I also wanted it to be able to work on its own.
There were several challenges to this approach. Firstly, to deal with user login in a way that would work with the project’s existing user system. Secondly, to validate all the input (for that, I used my Table Manager, which gives me a simple approach for generating and executing SQL to manage database tables and supports validation so that no data can be selected, inserted or updated in the database without it being validated and sanitized first – I will be posting this soon). My third goal was to make it beautiful, easy to use, fast, and with as many advanced features as possible (for example, filtering results, creating/editing/deleting with ajax when available, among others), so that the end result was actually better than most administration control panels I’ve ever seen or made.
I will follow up on this post later this week with another post for the release of a 1.0 release. I will spend this final week finishing some important features that I need for the 1.0 and working out the kinks.
