布局在 Laravel 4 中抛出“尝试分配非对象的属性”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18678640/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 08:23:53  来源:igfitidea点击:

Layouts Throwing "Attempt to assign property of non-object" In Laravel 4

phplayoutlaravelblade

提问by Joshua Ziering

In the Layouts folder, I have a layout called signup.blade.php

在 Layouts 文件夹中,我有一个名为 signup.blade.php 的布局

In my controller, I'm assigning a layout to it like so:

在我的控制器中,我为它分配了一个布局,如下所示:

    protected $layout = 'layouts.signup';

In a separate folder, named "signup" I have a file called "signup1.blade.php" It contains your typical blade template stuff. It's a section called "content". Before the code I have

在一个名为“signup”的单独文件夹中,我有一个名为“signup1.blade.php”的文件,它包含典型的刀片模板内容。这是一个名为“内容”的部分。在我拥有的代码之前

@section('content')

and it's got @stop at the end.

最后还有@stop。

My controller looks like this:

我的控制器看起来像这样:

public function SignUp()
{       
    $this->layout->content = View::make('signup.signup1');
}

The frustrating part is that this is working with another layout and controller. I've double checked they're the same, and this one does not work. Any suggestions would be greatly appreciated. Thank you.

令人沮丧的是,这是与另一个布局和控制器一起工作的。我仔细检查过它们是一样的,这个不起作用。任何建议将不胜感激。谢谢你。

回答by fideloper

So, assuming this controller extends BaseController (it must for $layout to work), the code execution sets$this->layoutto View::make($this->layout).

所以,假设这个控制器扩展了 BaseController(它必须让 $layout 工作),代码执行设置$this->layoutView::make($this->layout).

Your error seems to show that $this->layoutis not getting set to a View object correctly.

您的错误似乎表明$this->layout未正确设置为 View 对象。

Try to run this and see if $this->layoutis an object/class, and if so, what class it is.

尝试运行它,看看它是否$this->layout是一个对象/类,如果是,它是什么类。

public function SignUp()
{       
    echo gettype($this->layout);
    echo get_class($this->layout);
}

Knowing what $this->layoutdoes not get changed into a Viewobject means that the setupLayout()method is either not called or, more likely, not the result of View::make($this->layout)is not a proper view (perhaps it's silently failing for some reason).

知道什么$this->layout没有变成View对象意味着 setupLayout()方法要么没有被调用,要么更有可能不是结果View::make($this->layout)不是一个正确的视图(也许它出于某种原因默默地失败了)。

The above steps hopefully give you a clue into whats happening there. Perhaps layouts.signupisn't a layout the app is finding?

以上步骤有望让您了解那里发生的事情。也许layouts.signup不是应用程序正在寻找的布局?

What do your routes look like?

你的路线是什么样的?

回答by malhal

Change

改变

class UsersController extends Controller

to

class UsersController extends BaseController

Hopefully the author of Confide fixes this :-)

希望Confide的作者解决这个问题:-)