Form - Passing array from controller to view - PHP - Laravel -
Form - Passing array from controller to view - PHP - Laravel -
i'm new laravel, , i'm not sure know i'm doing. have form in main view. i'm passing input controller, , want info displayed in view. can't seem array controller sec view. maintain getting 500 hphp_invoke. here's i'm passing array controller view2.
public function formsubmit() { if (input::post()) { $name = input::get('name'); $age = input::get('age'); $things = array($name, $age); homecoming view::make('view2', array('things'=>$things)); } }
view1.blade.php
{{ form::open(array('action' => 'controller@formsubmit')) }} <p>{{ form::label('name') }} {{ $name = form::text('name') }}</p> <p>{{ form::label('age') }} {{ $age = form::text('age') }}</p> <p>{{ form::submit('submit') }}</p> {{ form::close() }}
my view2.php file simple.
<?php echo $name; echo $age; ?>
then in routes.php
route::get('/', function() { homecoming view::make('view1'); }); route::post('view2', 'controller@formsubmit');
why isn't working?
try with()
$data = array( 'name' => $name, 'age' => $age ); homecoming view::make('view2')->with($data);
on view :- echo $data['name']; echo $data['age'];
or
return view::make('view2')->with(array('name' =>$name, 'age' => $age));
get on view :-
echo $name; echo $age;
for more follow here
php arrays laravel view controller
Comments
Post a Comment