【问题标题】:How to solve FatalErrorException (E_UNKNOWN) Cannot use [] for reading?如何解决 FatalErrorException (E_UNKNOWN) 无法使用 [] 读取?
【发布时间】:2019-12-09 05:16:06
【问题描述】:

每当我想查看个人资料时,它都会向我显示一个致命错误,并显示消息

致命错误异常 (E_UNKNOWN) 无法使用 [] 阅读

为什么会这样

@if($user->is_employer() || $user->is_agent())
                <div class="profile-company-logo mb-3">
                    <img src="{{ $user->logo_url[] }}" class="img-fluid" style="max-width: 100px;" />
                </div>
            @endif

            <table class="table table-bordered table-striped mb-4">

                <tr>
                    <th>@lang('app.name')</th>
                    <td>{{ $user->name }}</td>
                </tr>

                <tr>
                    <th>@lang('app.email')</th>
                    <td>{{ $user->email }}</td>
                </tr>
                <tr>
                    <th>@lang('app.gender')</th>
                    <td>{{ ucfirst($user->gender) }}</td>
                </tr>
                <tr>
                    <th>@lang('app.phone')</th>
                    <td>{{ $user->phone }}</td>
                </tr>
                <tr>
                    <th>@lang('app.address')</th>
                    <td>{{ $user->address }}</td>
                </tr>
                <tr>
                    <th>@lang('app.country')</th>
                    <td>
                        @if($user->country)
                            {{ $user->country->name }}
                        @endif
                    </td>
                </tr>

                <tr>
                    <th>@lang('app.created_at')</th>
                    <td>{{ $user->signed_up_datetime() }}</td>
                </tr>
                <tr>
                    <th>@lang('app.status')</th>
                    <td>{{ $user->status_context() }}</td>
                </tr>
            </table>




            @if($user->is_employer() || $user->is_agent())
                    <h3 class="mb-4">About Company</h3>

                    <table class="table table-bordered table-striped">
                    <tr>
                        <th>@lang('app.state')</th>
                        <td>{{ $user->state_name }}</td>
                    </tr>
                    <tr>
                        <th>@lang('app.city')</th>
                        <td>{{ $user->city }}</td>
                    </tr>

                    <tr>
                        <th>@lang('app.website')</th>
                        <td>{{ $user->website }}</td>
                    </tr>
                    <tr>
                        <th>@lang('app.company')</th>
                        <td>{{ $user->company }}</td>
                    </tr>
                    <tr>
                        <th>@lang('app.company_size')</th>
                        <td>{{company_size($user->company_size)}}</td>
                    </tr>
                    <tr>
                        <th>@lang('app.about_company')</th>
                        <td>{{ $user->about_company }}</td>
                    </tr>
                    <tr>
                        <th>@lang('app.premium_jobs_balance')</th>
                        <td>{{ $user->premium_jobs_balance }}</td>
                    </tr>
                </table>
            @endif


            @if( ! empty($is_user_id_view))
                <a href="{{route('users_edit', $user->id )}}">
                    <i class="la la-pencil-square-o"></i> @lang('app.edit') </a>
            @else
                <a href="{{ route('profile_edit') }}"><i class="la la-pencil-square-o"></i> @lang('app.edit') </a>
            @endif

单击编辑按钮后,我想查看个人资料并进行编辑。

【问题讨论】:

  • logo_url[] - 有错字吗??
  • 你为什么在里面使用[]
  • 好的,它对用户有用,但是,仍然显示“htmlspecialchars() 期望参数 1 是字符串,数组给定”这个给雇主。
  • htmlspecialchars 的用法在哪里?该消息应该告诉您您需要知道的一切,expects parameter 1 to be string, array given。你有一个数组,而不是一个字符串。该函数适用于字符串。
  • htmlspecialchars() 每次调用{{ $... }} 时都会运行;它是blade 模板引擎的一部分。本质上,{{ }} 中的内容是array 而不是string,因此您需要循环该变量才能使用它。喜欢{{ $user-&gt;logo_url[] }}

标签: php database laravel codeigniter web


【解决方案1】:

这行没有意义:

if ($user->is_employer() || $user->is_agent()) logo_url[]

如果条件为真,你正在运行:

logo_url[]

这是一个语法错误。这似乎是一个错字,你可能只是想要这个:

if ($user->is_employer() || $user->is_agent())

【讨论】:

  • 从 logo_url 中删除 [ ] 后,它向我显示“htmlspecialchars() 期望参数 1 是字符串,给定数组”这个给雇主。
  • @user3783243 奇怪,在你编辑之前它是这样渲染的,但我懒得去修复它。
猜你喜欢
  • 1970-01-01
  • 2018-08-03
  • 2022-01-26
  • 2017-12-02
  • 2019-04-30
  • 1970-01-01
  • 1970-01-01
  • 2020-07-30
  • 2019-11-21
相关资源
最近更新 更多