<i id='UkpX0'><tr id='UkpX0'><dt id='UkpX0'><q id='UkpX0'><span id='UkpX0'><b id='UkpX0'><form id='UkpX0'><ins id='UkpX0'></ins><ul id='UkpX0'></ul><sub id='UkpX0'></sub></form><legend id='UkpX0'></legend><bdo id='UkpX0'><pre id='UkpX0'><center id='UkpX0'></center></pre></bdo></b><th id='UkpX0'></th></span></q></dt></tr></i><div id='UkpX0'><tfoot id='UkpX0'></tfoot><dl id='UkpX0'><fieldset id='UkpX0'></fieldset></dl></div>

    <small id='UkpX0'></small><noframes id='UkpX0'>

      <bdo id='UkpX0'></bdo><ul id='UkpX0'></ul>

      <legend id='UkpX0'><style id='UkpX0'><dir id='UkpX0'><q id='UkpX0'></q></dir></style></legend>
      1. <tfoot id='UkpX0'></tfoot>

        将变量从控制器传递到视图 - Laravel

        时间:2023-10-02
        • <tfoot id='ks7C2'></tfoot>

            • <small id='ks7C2'></small><noframes id='ks7C2'>

                <bdo id='ks7C2'></bdo><ul id='ks7C2'></ul>
                <legend id='ks7C2'><style id='ks7C2'><dir id='ks7C2'><q id='ks7C2'></q></dir></style></legend>
                  <i id='ks7C2'><tr id='ks7C2'><dt id='ks7C2'><q id='ks7C2'><span id='ks7C2'><b id='ks7C2'><form id='ks7C2'><ins id='ks7C2'></ins><ul id='ks7C2'></ul><sub id='ks7C2'></sub></form><legend id='ks7C2'></legend><bdo id='ks7C2'><pre id='ks7C2'><center id='ks7C2'></center></pre></bdo></b><th id='ks7C2'></th></span></q></dt></tr></i><div id='ks7C2'><tfoot id='ks7C2'></tfoot><dl id='ks7C2'><fieldset id='ks7C2'></fieldset></dl></div>
                    <tbody id='ks7C2'></tbody>

                  本文介绍了将变量从控制器传递到视图 - Laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在尝试将一个变量从一个视图传递到另一个视图的控制器.我没有收到任何错误,但是当它进入最后一个视图时,它没有像预期的那样显示变量.在第一个视图中,我只是得到一个名字.

                  I'm trying to pass a variable from one view to a controller to another view. I'm not getting any errors, but when it gets to the last view, it doesn't show the variable like it's supposed to. In the first view, I'm just getting a name.

                  {{ Form::open(array('route' => 'form', 'method'=>'post')) }}
                      {{ $name = Form::text('name') }}
                      {{ Form::submit('Go!') }}
                  {{ Form::close() }}
                  

                  这是我的 HomeController.php.

                  Here is my HomeController.php.

                  public function view1()
                  {
                      return View::make('stuff');
                  }
                  
                  public function postView1($name)
                  {
                      return Redirect::route('view2')->with($name);
                  }
                  
                  public function view2($name)
                  {
                      return View::make('view2')->with($name);
                  }
                  

                  routes.php

                  Route::get('/', array('as' => 'stuff', 'uses' => 'HomeController@stuff'));
                  Route::post('form/{name}', array('as' => 'form', 'uses'=>'HomeController@postView1'));
                  Route::get('view2/{name}', array('as' => 'view2', 'uses' => 'HomeController@view2'));
                  

                  view2.blade.php

                  view2.blade.php

                  {{ $name = Input::get('name') }}
                  <p> Hello, {{ $name }} </p>
                  

                  那为什么不显示呢?

                  推荐答案

                  首先你应该把你的 postView 函数改成:

                  First you should change your postView function into:

                  public function postView1()
                  {
                      return Redirect::route('view2', ['name' => Input::get('name')]);
                  }
                  

                  还有你的路线:

                  Route::post('form/{name}', array('as' => 'form', 'uses'=>'HomeController@postView1'));
                  

                  进入:

                  Route::post('form', array('as' => 'form', 'uses'=>'HomeController@postView1'));
                  

                  现在,您应该将 view2 函数更改为:

                  Now, you should change your view2 function into:

                  public function view2($name)
                  {
                      return View::make('view2')->with('name',$name);
                  }
                  

                  现在在您的 view2.blade.php 中,您应该可以使用:

                  Now in your view2.blade.php you should be able to use:

                  <p> Hello, {{ $name }} </p>
                  

                  这篇关于将变量从控制器传递到视图 - Laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel 中 View Composer 和 Creator 的区别? 下一篇:一个 RESTful 持久性解决方案,可用于 Backbone.js.

                  相关文章

                  最新文章

                  <i id='auETO'><tr id='auETO'><dt id='auETO'><q id='auETO'><span id='auETO'><b id='auETO'><form id='auETO'><ins id='auETO'></ins><ul id='auETO'></ul><sub id='auETO'></sub></form><legend id='auETO'></legend><bdo id='auETO'><pre id='auETO'><center id='auETO'></center></pre></bdo></b><th id='auETO'></th></span></q></dt></tr></i><div id='auETO'><tfoot id='auETO'></tfoot><dl id='auETO'><fieldset id='auETO'></fieldset></dl></div>
                  1. <small id='auETO'></small><noframes id='auETO'>

                      <bdo id='auETO'></bdo><ul id='auETO'></ul>

                    1. <tfoot id='auETO'></tfoot>
                    2. <legend id='auETO'><style id='auETO'><dir id='auETO'><q id='auETO'></q></dir></style></legend>