Codeigniter -> function using empty_table
Codeigniter -> function using empty_table
I am trying to empty the tables but I was wondering have I got the function correct?
Model:
public function removeQuote()
$this->db->empty_table('companyDetails,hostingDetails,layoutDetails');
Controller:
public function submit()
$data['companyContact'] = $this->quote->getCompanyDetails()->companyContact;
$this->load->view('submit',$data);
$this->quote->removeQuote();
Error:
Table '_quote.companyDetails,hostingDetails,layoutDetails' doesn't exist
DELETE FROM `companyDetails,hostingDetails,layoutDetails`
2 Answers
2
/**
* Empty Table
*
* Compiles a delete string and runs "DELETE FROM table"
*
* @param string the table to empty
* @return object
*/
public function empty_table($table = '')
Apparently you can't do this
$this->db->empty_table('companyDetails,hostingDetails,layoutDetails');
Instead you will have to call empty_table three times:
empty_table
$this->db->empty_table('companyDetails');
$this->db->empty_table('hostingDetails');
$this->db->empty_table('layoutDetails');
You can always hack CodeIgniter DB_active_rec.php file so that it fits your needs.
In your controller you have to load the model first (if it's not auto loaded)
$this->load->model('quote'); // Assuming your model name is 'quote'
before you use the function from that model as you used in your controller as follows
$data['companyContact'] = $this->quote->getCompanyDetails()->companyContact;
and load the view at last, after all code has been executed even after following line
$this->quote->removeQuote();
Just checked in CI doc empty_table doesn't accept multiple table names.
CI
empty_table
__construct ()
empty_tables ()
I have got my model auto loaded and please see here: codeigniter.com/user_guide/database/active_record.html#delete
– Jess McKenzie
Apr 9 '12 at 0:40
Got it, thanks.
– The Alpha
Apr 9 '12 at 0:42
Ok, didn't know about that! but please show us your error log
– novato
Apr 9 '12 at 0:43
No, it doesn't, I have just seen it in CI system code
– novato
Apr 9 '12 at 0:49
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
maybe he first loaded it in his
__construct (), is there really a method calledempty_tables ()in the Database class of CodeIgniter?– novato
Apr 9 '12 at 0:37