Welcome Guest, Not a member yet? Register   Sign In
Global functions
#7

[eluser]mddd[/eluser]
You can. If you use this code in your view.
Code:
$CI =& get_instance();
// $CI can now be used the same as you would use $this in your controller.
// for instance:
$CI->my_library->my_function();

Whether you want to do it this way or a different way is mainly a matter of taste.
Somehow it feels better to me to put the libray call in the controller and pass the data to the view.
I think it's because I like to keep the view as 'dumb' as possible.
For instance:
Code:
// this is in the controller
$this->load->library('my_library');
$data = $my_library->get_my_data();
$this->load->view('my_view', $data);
If you wanted to make that shorter you could autoload the library. You could even set the data from the library using
Code:
$this->load->vars($data); // after this, $data is pushed to every view you load!
This would automate it completely; you wouldn't have to do anything in the controller or the view, to have the data available.


Messages In This Thread
Global functions - by El Forum - 08-18-2010, 09:02 PM
Global functions - by El Forum - 08-18-2010, 11:44 PM
Global functions - by El Forum - 08-19-2010, 12:15 AM
Global functions - by El Forum - 08-19-2010, 07:30 AM
Global functions - by El Forum - 08-19-2010, 07:37 AM
Global functions - by El Forum - 08-19-2010, 07:45 AM
Global functions - by El Forum - 08-19-2010, 07:55 AM
Global functions - by El Forum - 08-19-2010, 08:31 AM
Global functions - by El Forum - 08-19-2010, 10:04 AM
Global functions - by El Forum - 08-19-2010, 10:27 AM
Global functions - by El Forum - 08-19-2010, 10:29 AM
Global functions - by El Forum - 08-19-2010, 10:39 AM
Global functions - by El Forum - 08-19-2010, 10:43 AM
Global functions - by El Forum - 08-30-2010, 11:06 AM
Global functions - by El Forum - 08-30-2010, 01:26 PM



Theme © iAndrew 2016 - Forum software by © MyBB