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.
7 comments
Hi Matthew,
Is it possible to give us an example of use for your class?
thanks
Christos
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!!
Thanks for this! One question. How can I include two image upload fields?
Thanks again!
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.
I used this in the past and I am getting back at it now. This is great. Thanks for sharing this
Thank You very much for posting your scaffolding routine. I’ve been working on one of my own for some time now, but got a great idea on the if (substr($column, -3) == “_id”).
WHen I tried to look at the page you reference in your scaffolding class, I was redirected somewhere else so I decided to do a google search on “39-Creating-A-Scaffold-like-Class-in-PHP-or-An-Automatic-CMS-For-a-Table”, but got the warning below…
I thought I’d let you know that you might want to post the warning below on your tutorial, or at least make people aware in case they are not using google to find the reference.
I was going to send you a screen capture of the warning, but didn’t see any way to send it to you, so I copied and pasted the text of the warning…
Best Regards,
Bill Hernandez
Plano, Texas
WARNING
Safe Browsing
Diagnostic page for tutorialhero.com
What is the current listing status for tutorialhero.com?
Site is listed as suspicious – visiting this web site may harm your computer.
Part of this site was listed for suspicious activity 3 time(s) over the past 90 days.
What happened when Google visited this site?
Of the 2895 pages we tested on the site over the past 90 days, 330 page(s) resulted in malicious software being downloaded and installed without user consent. The last time Google visited this site was on 2010-12-30, and the last time suspicious content was found on this site was on 2010-12-30.
Malicious software includes 291 trojan(s). Successful infection resulted in an average of 1 new process(es) on the target machine.
Malicious software is hosted on 36 domain(s), including expa82.co.cc/, expa81.co.cc/, expa80.co.cc/.
7 domain(s) appear to be functioning as intermediaries for distributing malware to visitors of this site, including govtds02.co.cc/, tutorialjungle.com/, studiovarna.com/.
This site was hosted on 1 network(s) including AS20773 (HOSTEUROPE).
Has this site acted as an intermediary resulting in further distribution of malware?
Over the past 90 days, tutorialhero.com appeared to function as an intermediary for the infection of 1 site(s) including tutorialkit.com/.
Has this site hosted malware?
No, this site has not hosted malicious software over the past 90 days.
How did this happen?
In some cases, third parties can add malicious code to legitimate sites, which would cause us to show the warning message.
Next steps:
Return to the previous page.
If you are the owner of this web site, you can request a review of your site using Google Webmaster Tools. More information about the review process is available in Google’s Webmaster Help Center.
Excelent software!
Our apologies, you must be logged in to post a comment.