Laravel错误:方法Illuminate \ View \ View :: __ toString()不得引发异常 [英] Laravel Error: Method Illuminate\View\View::__toString() must not throw an exception

查看:1071
本文介绍了Laravel错误:方法Illuminate \ View \ View :: __ toString()不得引发异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您在Laravel中工作时看到过这个可爱的错误吗?

Have you seen this lovely error while working in Laravel?

Method Illuminate\View\View::__toString() must not throw an exception

我已经看到了,这真令人讨厌.我发现了引发此错误的两个原因.我只是想帮助人们不要花费数小时的时间.

I have seen it and it's incredibly annoying. I have found out two reasons why this error gets thrown. I just want to help people not take hours and hours of time.

查看答案&下面的情况. :)

View answers & situations below. :)

推荐答案

情况1: 尝试在数组中打印出一个值.

Situation 1: Trying to print out a value in an array.

答案1: 尝试打印出阵列.您确定这是一个数组吗?当它是对象而不是数组时,出现了此错误.尝试做一个print_r,看看会得到什么.

Answer 1: Try printing out the array. Are you sure it's an array? I've gotten this error when it was an object instead of an array. Try doing a print_r and seeing what you get.

情况2: 您具有以下关联数组:

Situation 2: You have this associated array like this:

Array
    (
        [post_id] => 65
        [post_text] => Multiple Images!
        [created_at] => 2014-10-23 09:16:46
        [updated_on] => 
        [post_category] => stdClass Object
            (
                [category_label] => Help Wanted
                [category_code] => help_wanted
            )

        [employee_full_name] => Sam Jones
        [employee_pic] => /images/employee-image-placeholder.png
        [employee_email] => jon@gmail.com
        [post_images] => Array
            (
                [0] => stdClass Object
                    (
                        [image_path] => 9452photo_2.JPG
                    )

                [1] => stdClass Object
                    (
                        [image_path] => 8031photo_3.JPG
                    )

            )

    )

当您尝试直接在View中访问post_images数组时,它将引发错误. 否.事情.什么.你.做.

When you try to access post_images array directly within a View, it throws an error. No. Matter. What. You. Do.

答案2: 检查所有要调用视图"的地方.这里发生的是,我试图在未提供post_images数组的区域中的其他位置访问相同的视图.永远花了一点时间.

Answer 2: Check in all the places where you are calling the View. What happened here is that I was trying to access the same view somewhere else in an area where I wasn't giving the post_images array. Took FOREVER to figure out.

我希望这对其他人有帮助. :)我只知道我一直遇到的错误并没有对我有所帮助.

I hope this helps someone else. :) I just know the error I kept getting didn't help me anywhere.

这篇关于Laravel错误:方法Illuminate \ View \ View :: __ toString()不得引发异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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