Jump to content


Set table name from GET variable.

get variable table

  • Please log in to reply
6 replies to this topic

#1 avestavik

avestavik

    Newbie

  • Members
  • Pip
  • 4 posts

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


Edited by avestavik, 30 March 2017 - 05:24 AM.


#2 xheradon

xheradon

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts
  • LocationSpain

Posted 30 March 2017 - 07:07 AM

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



#3 avestavik

avestavik

    Newbie

  • Members
  • Pip
  • 4 posts

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 ;-)



#4 xheradon

xheradon

    Advanced Member

  • Members
  • PipPipPip
  • 47 posts
  • LocationSpain

Posted 30 March 2017 - 10:46 AM

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



#5 avestavik

avestavik

    Newbie

  • Members
  • Pip
  • 4 posts

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... 



#6 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

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 :)



#7 avestavik

avestavik

    Newbie

  • Members
  • Pip
  • 4 posts

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. 







Also tagged with one or more of these keywords: get, variable, table

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users