laraver框架中给模板分配数据

(一)给模板分配数据

            (1)在控制器中给模板分配数据

                     return view('firstclass.index',['name'=>'Alice','number'=>123]);

                      在模板中获取数据时需要两层{{$name}}

              (2)使用return view('firstclass.index')->with('name','Jerry')->with('password','123456');

      注意:在模板中注释代码时使用html注释,上一次的变量将会无法无法注释,需要在变量两侧加上--

     eg:{{--$name--}}

            (3)使用  $str1='welcome';
                              $str2="Alice";

                              return view('firstclass.index',compact('str1','str2'));


猜你喜欢

转载自blog.csdn.net/i_am_lonely/article/details/79965112