Welcome Guest, Not a member yet? Register   Sign In
Passing data to view
#8

[eluser]mddd[/eluser]
The compact() function in php is something many people don't know about.
It is used to make an array with simple key names. It can be very handy in this context.
Example:
Code:
// some variables
$test = 'Some text';
$products = $this->product_model->get_newest(10);
// now give these variables to the view
$this->load->view('myview', compact('test','products'));
// $test and $products are now available in the view!
// because compact('test','products') gives you : array('test'=>$test, 'products'=>$products)


Messages In This Thread
Passing data to view - by El Forum - 07-20-2010, 07:03 AM
Passing data to view - by El Forum - 07-20-2010, 07:06 AM
Passing data to view - by El Forum - 07-20-2010, 07:08 AM
Passing data to view - by El Forum - 07-20-2010, 07:09 AM
Passing data to view - by El Forum - 07-20-2010, 07:10 AM
Passing data to view - by El Forum - 07-20-2010, 07:11 AM
Passing data to view - by El Forum - 07-20-2010, 07:15 AM
Passing data to view - by El Forum - 07-20-2010, 07:32 AM
Passing data to view - by El Forum - 07-20-2010, 09:09 AM
Passing data to view - by El Forum - 07-20-2010, 09:13 AM
Passing data to view - by El Forum - 07-20-2010, 09:13 AM
Passing data to view - by El Forum - 07-20-2010, 09:15 AM
Passing data to view - by El Forum - 07-20-2010, 09:16 AM
Passing data to view - by El Forum - 07-20-2010, 09:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB