Welcome Guest, Not a member yet? Register   Sign In
Error trying to load a library inside the view
#2

[eluser]Jamie Rumbelow[/eluser]
The simple answer here is don't! It's never a good idea to call libraries within your views - that's what your controllers and models are for. Instead of loading and referencing the library within your view, load it and get the data you need in your controller then pass that to the view to display it. A quick example:

Code:
//Controller
$this->load->library('search_vehicle_params_manager');

$data['search_vehicle_type'] = $this->search_vehicle_params_manager->get_param_value(Search_vehicle_params_manager::VEHICLE_TYPE);
$this->load->view('header', $data);

Then, in your view, you can access the data as a variable:

Code:
<p>Type: &lt;?=$search_vehicle_type?&gt;</p>

By convention you won't ever want to call libraries in your views - it clogs them up and makes them messy. Instead move this functionality into the controller or model and clean up the view, minimising logic and making the view nice and pretty.

Jamie


Messages In This Thread
Error trying to load a library inside the view - by El Forum - 11-08-2009, 02:25 PM
Error trying to load a library inside the view - by El Forum - 11-08-2009, 02:34 PM
Error trying to load a library inside the view - by El Forum - 11-08-2009, 07:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB