• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
One Scaffolding to rule them all

[eluser]Michael Ekoka[/eluser]
Since the aim of Scaffolding is to quickly access tables in the db, I find it simpler to have one controller solely used for that purpose.
I use something like this:
class Scaffold_controller extends Controller{
    public function __construct(){
            $_SESSION[APPPATH]['table_to_scaffold']= $this->uri->segment(3);

Then to scaffold a table, in my url I can simply enter the name of the table and authorize the switch:

in reality it would look more like this :

As have been said by wiser men than me, use scaffold with lots of caution and in dev only.

You could have that less redundant if you just check $this->uri->segment(x) (forgot, which one it was) against the scaffold trigger ...

[eluser]Michael Ekoka[/eluser]
Quote:You could have that less redundant if you just check $this->uri->segment(x) (forgot, which one it was) against the scaffold trigger

I'm not sure what you mean, but i'll try to explain the logic behind what i did, if you have a workaround for the problem that i encountered please share:

the original structure of the scaffolding link, i.e. the way CI currently expects it to be submitted is:


Then, from the controller one would load the scaffolding, select the table to scaffold, etc. The problem is that you have to revert to the controller each time you need to switch tables, since the url does not include which table is involved. Everything is expected to be found in the controller's constructor. So to add that capability from the url, I decided to add the third argument to the link, making it:


The value would then easily be retrieved from the $this->uri->segment(3). Unfortunately the urls automatically generated in the scaffolding views by the core mechanism (edit, add, delete) also ignore which table is involved and only know 3 things:


I really wanted to keep the code unobtrusive and rather than modifying the core scaffolding library to include the db table name in the urls generated for the views, I chose to store that value in a session, hence:
($_SESSION[APPPATH]['table_to_scaffold']= $this->uri->segment(3);)

Only one problem, during scaffolding actions, the third argument in the url (action_to_perform) could overwrite my table name. To avoid this, I need to put a flag that authorizes the rewriting, hence:
    $_SESSION[APPPATH]['table_to_scaffold']= $this->uri->segment(3);

and that flag is included in the url as :


So if your database has a table called "edit" you can select the table with
and edit a record in that table with:

I could probably include a list of reserved action names in an array and exclude them from possible table names, but who knows the next time someone might need to call a table "edit".

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.