简体   繁体   English

带有 Laravel 和刀片的未定义变量

[英]Undefined variable with laravel and blade

I know it's probably super simple, but I just started using laravel today, I've always been on codeigniter before.我知道这可能非常简单,但我今天才开始使用 laravel,我以前一直在使用 codeigniter。 The problem I have is that laravel tells me that my variable is not defined ...我遇到的问题是 Laravel 告诉我我的变量没有定义......

Controller:控制器:

public function index()
{

    $data['pageTitle']='Connexion';

    return view('login')->with($data);
}

The line concerned in login.blade.php: login.blade.php 中的相关行:

@extends('layout.header', $pageTitle)

Error:错误:

"Undefined variable: pageTitle (View: G:\Winginx\home\laravel\public_html\resources\views\login.blade.php)"

Thanks !谢谢 !

You're getting this error because you're trying to use $pageTitle variable but you do not pass it to the view.您收到此错误是因为您尝试使用$pageTitle变量,但没有将其传递给视图。

So, to fix this you can change this line in the view:因此,要解决此问题,您可以在视图中更改此行:

@extends('layout.header', $data['pageTitle'])

Or you can change method in controller to:或者您可以将控制器中的方法更改为:

public function index()
{
    return view('login', ['pageTitle' => 'Connexion']);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM