⚠ 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

Set table name from GET variable.



avestavik
  • profile picture
  • Member

Posted 30 March 2017 - 05:23 AM

Hi, 

 

I'm going straight to the point. I need to define the table name from GET variable. This variable is named "table".

 

Here you can see my code:

	public function crud(){
		//Fetching the GET variable into variable for easier use.
		$table = $this->input->get('table');

		//Load of CRUD and load it. 
		$this->load->library('grocery_CRUD');
		$crud = new grocery_CRUD();

		//Setting CRUD attributes.
	        $crud->set_table($table);
		$crud->set_subject($table);

		//Rendering it and loading the view with the data. 
		$data["output"] = $crud->render();
		$data["view"] = "data/crud";
    	        $this->load->view('layouts/main', $data);
	}

But issue comes when I do the create function, then I lose the GET variable. 

Error:

Message: The table name cannot be empty.

 

Anyone got any good tips or tricks to get this sorted?

 

Thanks in advance. 

 

Best Regards


xheradon
  • profile picture
  • Member

Posted 30 March 2017 - 07:07 AM

And if you declare a variable with the table name before functions?


avestavik
  • profile picture
  • Member

Posted 30 March 2017 - 08:22 AM

Hi, thanks. 

 

Where do you recon that I declare this variable?

 

Just started using GroceryCRUD as you may understood ;-)


xheradon
  • profile picture
  • Member

Posted 30 March 2017 - 10:46 AM

I mean to declare $table as global so you can access to it within your function.


avestavik
  • profile picture
  • Member

Posted 30 March 2017 - 11:04 AM

What I did was added this to the top section of the function:

		//Fetching the GET variable into variable for easier use.
		//Using session variable to enable create/update
		if(isset($_GET["table"])){
			$table = $_GET["table"];
			$this->session->set_userdata('table', $_GET["table"]);
		}else{
			$table = $this->session->userdata('table');
		}

I'm feeling that this is not the best way of doing it, but it works... 


Amit Shah
  • profile picture
  • Member

Posted 30 March 2017 - 11:06 AM

well i dont really think u need to declare the table name .. hes actually planning to pass the table name and show the crud basis the table name. 

Now there is a catch to the same ... or a problem to the same -u may need to be lucky to have the parameter being added along.. else - next query that will be executed - u may loose  the data. It must pass on along with the params set - i just was skeptical as i never tried it and seen it in action.

 

Happy GCing :)


avestavik
  • profile picture
  • Member

Posted 30 March 2017 - 12:56 PM

Thanks. Have tested this now for about 100 records, seems to work fine. 

But I guess if you have to work with multiple create/update forms at the same time this will not work. 

 

Will try to send this out to the testing person today or tomorrow for testing.