将数据传递到视图laravel [英] passing data to a view laravel

查看:197
本文介绍了将数据传递到视图laravel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

只需进入mvc框架,并尝试使用刀片模板引擎将数据传递到我的视图即可.

Just getting to mvc frameworks and im trying to pass data to my view using blade template engine.

这是我的路线文件

Route::get('/', 'PagesController@index');

我的PagesController

my PagesController

<?php

namespace App\Http\Controllers;

use App\User;
use App\Http\Controllers\Controller;

class PagesController extends Controller {

    public function index() {

        return view('index');

        $url = 'example.com';
    }

    public function about() {


        return 'hello';


    }

}

我的index.blade.php文件

my index.blade.php file

<h1>{{ $url }}</h1>

我得到了Undefined variable:url错误消息.我在做什么错了?

I get the Undefined variable: url error message. What am i doing wrong?

推荐答案

尝试一下

public function index() {
   $url = 'example.com';
   return view('index', ['url' => $url]); 
}

初始化变量并将其作为参数发送到视图.

Initialize the variable and send it as a parameter to the view.

这篇关于将数据传递到视图laravel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆