[eluser]bleu[/eluser]
[quote author="oliur" date="1331917401"]This is wrong as far as MVC is concerend. You should be doing the other way around.
You do all processing in your controller and load your view from the controller.
But if you need to do any processing in the view use a helper instead.
Helpers are procedural functions just save them in your application/helper folder and call any function from view as and when required.
For example, I have a helper called application/helper/project_helper.php and a function called decode_id() within the helper.
If I need to use that function to decode an encrypted id from my view file, I do
Code:
// read encrypted id
$encrypted_id = $this->input->post('id');
// decode it
$decoded_id = decode_id($encrypted_id);
Notice you do not have to use $this-> as decode_id() is a procedural function.
If you need to interact with the database or access core classess from your helper you can't just use $this->db-.....
You need to create an object first from the helper.
Code:
$ci = & get_instance();
// you can use this object to access database or config/session etc
$ci->db-query('..');
or $ci->session->set_session('..','..')
Hope it helps.
[/quote]
Thanks that is helpful, but is this method proper , is it okay to pass a parameter to a helper from a view and get its data from the view?