These two pieces of code are equivalent:
$viewData = array('foo' => $bar);
return View::make('x', $viewData);
return View::make('x')->with('foo', $bar);
So in your second example, $viewData would have to have a key of 'viewData' to be equivalent to the first one.
So
return View::make('x')->with('foo', $bar);
only makes sense when i wanna send only one array/value to the View?
And if i have several arrays i do this?
$bar['city'] = array();
$bar['music'] = array();
$bar['location'] = array();
return View::make('x', $bar);
Instead of several with's like this:
return View::make('x')->with('city', array())->with('music', array())->with('location', array());
What's the best practice?
Thanks, Sharping
Sharping said:
So
return View::make('x')->with('foo', $bar);
only makes sense when i wanna send only one array/value to the View?
And if i have several arrays i do this?
$bar['city'] = array(); $bar['music'] = array(); $bar['location'] = array(); return View::make('x', $bar);
Instead of several with's like this:
return View::make('x')->with('city', array())->with('music', array())->with('location', array());
What's the best practice?
Thanks, Sharping
I generally the array method because it's less verbose, but it comes down to personal preference.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community