1 minute, 56 seconds
I have to admit, one of the utter joys of my job is that they encourage me to open source software I write at my day job. After looking high and low for a PHP framework or library to do a basic MySQL CRUD GUI, I gave up. While phpMyAdmin is the longstanding champion for full featured DB administration, it’s way to complicated for an end user looking to just add a row right quick. There seems to be an amazing project called CrudKit (great name!), but it has this one, massive blocking “feature”:
prevents usage in MVC frameworks
– commit 047807d01f
This is, literally, what I was trying to do. I spent a some time seeing how hard it would be to contribute to CrudKit to get the feature I wanted working. I ultimately decided that a bespoke solution would more quickly achieve my desired goals. That said, if you do want a stand alone app, do check out CrudKit.
While I suspect it could use some rewrites to not have silly-long arrays passed as arguments, I’m quite happy with my results: tableMaker. This guy takes this PHP:
$tm = new tableManager(DB_SERVER, DB_USER, DB_PASS, DATABASE, TABLE);
$rowsArray = $tm->getRowsFromTable();
print $tm->getHtmlFromRows($rowsArray, "/edit?table={$tm->table}&id=");
And turns it into this HTML:
If you want to render a fully functional edit form with dynamic client side error handling and table sensitive validation rules, just run this PHP:
$row = $tm->getRowFromTable($_GET['id']);
print $tm->getAddEditHtml($row, 'edit', "/save?table={$tm->table}");
Which will output this responsive, nice looking HTML:
Two big features of tableMaker are it’s simplicity and it’s security*. Yes table maker can do whiz bang client side sorting, but it also can output tidy, HTML compliant tables. Yes, we can make your browser download 100k+ of web fonts just to render an “X” when you have an error in your form, but it can also do with out all that noise – implementers choice! Security wise, tableMaker abstracts away all the complexity while ensuring there’s simply no way for you to expose yourself to a SQL injection attack. (* We need some nonces).
Along they way in making this, I see all the cool kids are using Composer. I’ve earmarked this guy for my next project!
I’m really happy to have been paid to write this library; I’d be even happier if some else on started using it! I’d about piss my pants with glee if some opened a PR ;)
Update 3/18/2017 – Issue #3 on tableManager has been closed – CSRF protection in place! Go Nonce, go!