php - Return a variable from a function to a view -


i newbie in laravel 4 , want return, when pressing button, value controller view.

my form view:

            {{ form::submit('save', array('class' => 'btn btn-small btn-info iframe')) }}             <?php             echo $test;             ?> 

my controller:

<?php class testcontroller extends basecontroller {       /**      * start scrapping script.      */     public function posttest() {         $scrap = 'it works!';          return view::make ( 'admin/test/index' )->with('test', $test);     } } 

my routes:

route::post('test', 'testcontroller@posttest'); 

however, get:

undefined variable: test(view: c:\xampp\htdocs\laravel_project\lara\app\views\admin\test\index.blade.php)  

any recommendations doing wrong?

i appreciate answer!

update

i changed controller that:

public function getindex() {      // show page     return view::make ( 'admin/test/index' ); }  public function posttest() {     $test = 'it works!';      return view::make ( 'admin/test/index' )->with('test', $test); } 

}

and added routes file:

route::get('test', 'testcontroller@getindex'); route::post('test', 'testcontroller@posttest'); route::controller('test', 'testcontroller'); 

furthermore, when calling:

                {{ $test}} 

i undefined variable: $test

any recommendations doing wrong?

you should change in controller:

return view::make ( 'admin/test/index' )->with('test', $test); 

to:

return view::make ( 'admin/test/index' )->with('test', $scrap); 

now getting undefined warning because there no $test variable in controller.

and in blade view, should display using:

{{ $test }} 

or

{{{ $test }}} 

(the second 1 escaping characters) , not <?php echo $test; ?>


Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -