Home > Development, PHP > PHP Scaffolding Class

PHP Scaffolding Class

August 15th, 2009

Im uploading this scaffolding class so that hopefully some other people can find use for it. It is based on the excellent tutorial on building a scaffolding class by Ben Hirsch which can be found here http://www.shadow-fox.net/site/tutorial/39-Creating-A-Scaffold-like-Class-in-PHP-or-An-Automatic-CMS-For-a-Table Sadly i can’t seem to find the original post however I’m sure its nothing a quick google can’t fix.

There is a link to the download at the end of this post.

I have used it to get projects going quickly. It can be pointed to a mysql database and can read the tables in etc and generate the CReate Update and Delete (CRUD) similar to how ruby on rails has scaffolding.

It is by no means perfect and could do with some refinements here and there. It is however quite functional in its current state and has support for foreign keys and image uploads.

There are some naming conventions to be adhered to if you want to get the most out of this. However you can quickly go through it and change these to whatever you like.

Here is a list of column names and how the Scaffolding Class reacts to them:

Column Name Data Type Scaffolding Output
image_url varchar(255) Image Upload Field
varchar Text Input
text Textarea
“foreigntable_id” INT Outputs the “name” field from the lookup table “foreigntable”
datetime A date/time drop down selector.
Last three characters ‘_on’ INT A Yes/No drop down selector.

I have used this for many projects to get them off the ground. For simple admin areas it works perfectly.

Would love to hear your thoughts and comments.

Download Scaffolding.zip

Development, PHP

  1. November 10th, 2009 at 12:40 | #1

    Hi Matthew,

    Is it possible to give us an example of use for your class?

    thanks

    Christos

  2. December 2nd, 2009 at 19:05 | #2

    Hi Christos

    Sorry for not getting back to you until now. I was working quite a lot through November. Here is a quick usage quide for how to use the php scaffolding class if you still need to know:

    in your scaffolding file there is the following line:

    new Scaffolding($table,”database_name”,”database_username”,”database_password”,”database_host”,$action);

    Change these details to match your databases settings.

    In your web browser navigate to where you stored the file on your web server eg http://www.foo.com/scaffolding.php

    This will then list the tables of your database which you can edit.

    If you have any other problems please just contact me I promise to reply much quicker next time!!

  3. Paul
    January 19th, 2010 at 22:58 | #3

    Thanks for this! One question. How can I include two image upload fields?

    Thanks again!

  4. February 11th, 2010 at 13:16 | #4

    Hi Paul thanks for getting in touch.

    I guess the easiest way would be to copy the image code and maybe add a “_1″ to it however this wouldn’t be the best way. It should be possible to modify the code slightly to just check if the fields first characters are “image_url” that way it would be possible to have fields such as “image_url_my_photo” or “image_url_news” etc. This would be the best way to go about it. The fields that end in “_on” could be a great base for a guide to changing the code.

    Please let me know how you get on and if there is anyway I can help you please do not hesitate to contact me.

    Thanks again.

  1. No trackbacks yet.