⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Variable set_table value



gray_penguin
  • profile picture
  • Member

Posted 06 February 2013 - 17:27 PM

I am trying to use this function in my CodeIgniter Controller:

function details($projectID = '', $message = '')
    {
        $data = $this->userDetails();
        $data['user_id'] = $this->tank_auth->get_user_id();
        $data['username'] = $this->tank_auth->get_username();
        $data['level'] = $this->tank_auth->get_userlevel();
        if($projectID == '')
        {
            $projectID = $this->input->post('id');
        }
        $processTable = "process".$projectID;
      
        // Grocery CRUD
        $this->load->library('grocery_CRUD');
        $crud = new grocery_CRUD();
        $crud->set_table($processTable);
        $crud->unset_export();
        $crud->unset_print();
        $crud->unset_add();
        $crud->unset_edit();
        $crud->unset_delete();
        $crud->add_action('Process', '/images/load.png', 'process/process','ui-icon-plus');
        $data['output'] = $crud->render();
        $this->load->view('process/details', $data);
    }

 

[You can see my tablename is variable.]

But when it renders on the view, it shows the data fine but the filter, sort, pagination, and search do not work.

If I set the set_table to one of the available tables, say [process1] then everything works fine in the view.

Is there a way to make one function work for one of many tables that have the same structure but different names?


victor
  • profile picture
  • Member

Posted 06 February 2013 - 18:21 PM

Hi gray_penguin and welcome to the forum! What error do you get? Have a look at the debug panel.

victor
  • profile picture
  • Member

Posted 06 February 2013 - 18:33 PM

if you haven't first segment(projectID) in your url, your code is wrong, because pagination search and sort use ajax , and request hasn't parameter "id". In your case $project is NULL

gray_penguin
  • profile picture
  • Member

Posted 06 February 2013 - 21:14 PM

Ahh, thanks.  I was thinking it had to have something to do with javascript/ajax not getting a variable that PHP has.  Now I have to figure out how to get the tablename in a place where JS can use it.


gray_penguin
  • profile picture
  • Member

Posted 06 February 2013 - 21:15 PM

the error was "table not found"