Welcome Guest, Not a member yet? Register   Sign In
Simple tool for Scaffolding to manage all tables faster
#1

[eluser]H. Bernaciak[/eluser]
Hello,

I have a great deal of hope, that it help although one of You to manage all tables in Scaffolding easier and faster. I have written it for my projects and use it still as well, bacause you can access any table much quicker than manual edit table name in controller.

Code:
<?php
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package        Scaffolding Manager Helper
* @author         Hubert Bernaciak
* @copyright      Copyright (c) 2007, Hubert Bernaciak.
* @link           http://www.hubi.pl
* @since          Version 1.0
*
*/

// ------------------------------------------------------------------------
class Manager extends Controller {

       function Manager()
       {
            parent::Controller();
            if(!$this->uri->segment(3) == '')
            {
            $this->load->scaffolding($this->uri->segment(3));
            }
       }
       function index()
       {
            $result = mysql_list_tables('homelab');
            while ($row = mysql_fetch_row($result))
            {
            echo '<a href="'.site_url('manager/SECRETPASSWORD').'/'.$row[0].'">'.$row[0].'</a><br />';
            }
      
       }
}
?&gt;

Code is very simple (probably not perfect), but feel free to ask Wink
#2

[eluser]daniel.affonso[/eluser]
Congrats and thanks for sharing.

Simplicity and result, Good!
#3

[eluser]sophistry[/eluser]
Thank you! This is nice.

Better db portablility may be achieved by using CI table listing function:
http://ellislab.com/codeigniter/user-gui..._data.html

EDIT: edited code for even better code portability. This is not the best, long-term way to get the scaffolding_trigger word, but it works.
Code:
// should be more portable, also not hard coded with db name
// since it is in config file already, code not tested on multiple dbs
// assumes db library is loaded
function index()
       {
           $tables = $this->db->list_tables();
            foreach ($tables as $table)
            {
            echo '<a href="'.site_url(__CLASS__.'/'.$this->uri->router->routes['scaffolding_trigger']).'/'.$table.'">'.$table.'</a><br />';
            }
       }
#4

[eluser]H. Bernaciak[/eluser]
yeah, it works also good and... is more IGNITER Tongue but everyone should remember about adding this at the beggining:

Code:
class Manager extends Controller {

       function Manager()
       {
            parent::Controller();
            if(!$this->uri->segment(3) == '')
            {
            $this->load->scaffolding($this->uri->segment(3));
            }
       }
#5

[eluser]sophistry[/eluser]
the whole code for easy copying.
Code:
&lt;?php
/**
* CodeIgniter
*
* An open source application development framework for PHP 4.3.2 or newer
*
* @package        Scaffolding Manager Helper
* @author         Hubert Bernaciak
* @copyright      Copyright (c) 2007, Hubert Bernaciak.
* @link           http://www.hubi.pl
* @since          Version 1.0
*
*/

// ------------------------------------------------------------------------
class Manager extends Controller {

       function Manager()
       {
            parent::Controller();
            if(!$this->uri->segment(3) == '')
            {
            $this->load->scaffolding($this->uri->segment(3));
            }
       }

       function index()
       {
           $tables = $this->db->list_tables();
            foreach ($tables as $table)
            {
            echo '<a href="'.site_url(__CLASS__.'/'.$this->uri->router->routes['scaffolding_trigger']).'/'.$table.'">'.$table.'</a><br />';
            }
       }
}
?&gt;
#6

[eluser]eljunior[/eluser]
I get and SQL error if i try to create a new record using this.

Quote:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'add LIMIT 1' at line 1

Did it happen to anyone of you? Or it's just my scaffolding that uses the third argument as the table name? (Or neither one? Big Grin)
#7

[eluser]sophistry[/eluser]
post your error and code and you'll get better help. but, anyway, this thread does not seem to pertain to your issue - this code is only for easily creating hyperlinks to scaffolding rather than creating records.

you have a SQL syntax error: 'add LIMIT 1' is being rejected. this little helper code shouldn't be the root of the problem. most likely you have a reserved word as a fieldname.
#8

[eluser]eljunior[/eluser]
sorry, I didn't explain it well.
the problem is, if i'm using correctly, the hyperlinks it's creating looks like this:

codeigniter/index.php/manager/SCAFF_TRIGGER/yourtable

which works fine, opening the scaffolding page for each table.
problem is, the scaffolding pages generated use links like this:

codeigniter/index.php/manager/SCAFF_TRIGGER/add

that's why it shows that SQL error.
(i don't know if there is someone who would use 'add' for a table name... Big Grin)

am I using this thing right?
by the way, thanks for the attention, sohpistry. Wink
#9

[eluser]sophistry[/eluser]
ok, eljunior... i have to admit that when i posted my code changes they were untested; i had not actually taken it out for a spin, i just assumed that the OP had gotten this to work in his setup and i was just coming along to make the code a little more portable.

really, i only posted to this thread because it was next door to a really nice thread about a working set of code called Matchbox. ;-) you should check it out if you haven't already.

as you've discovered. this code does not work as indicated.

i just tried it out and got the same error you did. SQL error complaining about add.

well, the reason it doesn't work took me a while to figure out... the scaffolding is only loaded properly when there is a tablename passed into its load function. so, it works fine to "get" to the list of records in scaffolding.

but, once you start to try to do anything, the scaffolding is the one in charge and it doesn't pass the table name along anymore, so the "manager" constructor actually passes the command "add" to SQL as the tablename. "add" is the 3rd segment and you see in the constructor that the 3rd segment is passed as the tablename. i'm sure that this code never actually *worked* for anyone - it gets you *to* the scaffolding record list, but then you can't do anything.

anyhow, i started trying to amend the code with an idea that you could store the actual tablename you were working in scaffolding (in a session var) and then pass it along to the scaffolding loader in the constructor but then i decided that the whole idea of automating scaffolding using this architecture was flawed to begin with. it could be done with the session var, but then you could only have one scaffolding "window" open at a time.

that's when i came back here to let you know my findings.

sorry for making it look like i was using the code! my bad.

welcome to CI, BTW. :-)
#10

[eluser]eljunior[/eluser]
I forgive you for making it look like you were using this and you forgive me for don't explaining the problem in detail... (though maybe I would have done this, if you didn't have done that. :-D :-D)

well, I think it's better I try to find another way to do this, then...

thanks a lot!




Theme © iAndrew 2016 - Forum software by © MyBB