databasecodeignitercontrollerpyrocmsdbforge

Trouble using dbforge with PyroCMS (CI based CMS)


I have been using PyroCMS and CI for quite some time, and truly love it.

I am extending a DB module that will allow an admin user to manage a DB without having to use something like phpMyAdmin.

The only thing I have been able to get working however is Browsing a table's field values (i.e 'SELECT * FROM 'table_name').

I want to include more functions, but I can't seem to get dbforge to work properly. I know it is loaded because dbforge is used to uninstall modules. I also get no error when calling functions from it.

Here is an example of my code from the controller (dbforge has already been loaded).

public function drop($table_name)
{
    $table_name = $this->uri->segment(4);
    $this->dbforge->drop_table($table_name);
    redirect('admin/database/tables');
}

Lets say the function gets called from this url:

.../admin/database/drop/table_name

It appears to work... but instead it just redirects to the tables overview.

Is there something I am missing? Shouldn't [$this->dbforge->drop_table($table_name);] always drop a table (given $table_name is valid)?

EDIT

As a work around, I was able to use:

public function drop($table_name)
{
    $table_name = $this->uri->segment(4);
    //$this->dbforge->drop_table($table_name);
    $this->db->query("DROP TABLE ".$table_name);
    redirect('admin/database/tables');
    return TRUE;
}

I really would like to use DB forge, however...


Solution

  • I think you might be getting a little confused by the site prefixes in PyroCMS 1.3.x.

    By default all installations of Community and Professional will have default_ as a prefix for all tables in the first site. If you have Professional you can add new sites and the site reference will be whatever_ instead of default_

    This prefix is accounted for by dbforge, so when you want to delete default_blog you would just delete:

    /admin/database/drop/blog

    Also, why are you accepting the $table_name as an argument then overriding it with a uri segment?

    Also, why are you accepting the $table_name as an argument then overriding it with a uri segment?

    See what I did there? xD

    public function drop($table_name)
    {
        $this->dbforge->drop_table($table_name);
        redirect('admin/database/tables');
    }