I’m building a CMS using CodeIgniter and I’m stumped on the best way to go about handling the various CRUD views. Given that my URL is similar to…
mydomain.com/admin/app/content/pages/edit
…where ‘admin’ is my controller and ‘app’ is my action method, I currently map segments 3, 4, and 5 to actual directories/files, like so:
/views
/admin
/content
/pages
list_view.php
edit_view.php
add_view.php
/banners
list_view.php
edit_view.php
add_view.php
One caveat is that I need to call different non-CRUD model methods depending on which page is being called, so my app() action method is starting to have have a nasty if..else block. Also, each section’s views are going to look different, because of different table data, so I don’t see how I can avoid having a bunch of view pages. Obviously the downside of all this is that 1) I’m repeating a lot of code, and 2) if I add a new admin section I have to physically make a slew of new directories and add a new portion to the if…else block.
So my questions are:
- How can I reduce the number of directories and view pages I’m creating?
- Can list_fields() or field_data() methods lend itself to any automation?
One idea I had was to profile the table I’m interacting with, create a dynamic associative array that defines which fields I want to expose as well as the type of form element it should be, and then pass that off to a common view. Thoughts? Flaws?
While this may not directly answer to your question, it may provide you with a basis on which to design your CRUD. I’ve used GroceryCRUD for quite a while now and pretty much swear by it for basic and advanced CRUD operations. It’s pretty well designed and built and apart from the bespoke file structure, would appear to offer all that you’re looking for.
The CRUD could easily be modified to incorporate the file/url structure you’re looking for too.
See http://www.grocerycrud.com/