Laravel 中的非法字符串偏移

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23447838/
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 09:28:03  来源:igfitidea点击:

Illegal string offset in Laravel

phplaravelget

提问by romeo

I'm using Laravel, and it complains about $header inside the Form::text being a illegal string offset, how do I fix this? It doesn't complain if I go straight into the page, but if I submit a form with get method going into the page. I searched around and maybe it thinks $header is an array?

我正在使用 Laravel,它抱怨 Form::text 中的 $header 是非法字符串偏移量,我该如何解决这个问题?如果我直接进入页面,它不会抱怨,但是如果我提交一个带有 get 方法进入页面的表单。我四处搜索,也许它认为 $header 是一个数组?

<?php 
        $header = null;
        if(isset($_GET["header"])) {
            $header = $_GET["header"];
        }

        echo Form::text('header', $header, array('class'=>'form-control', 'placeholder'=>'Tittel'));
?>

回答by Joel Hinz

Laravel clears the $_GET array. You need to use Input::has('header')and Input::get('header')instead.

Laravel 清除 $_GET 数组。您需要使用Input::has('header')andInput::get('header')代替。