Php 打印视图时的htmlspecialchars()
我得到一个错误: htmlspecialchars()要求参数1为字符串,对象为给定值 当打印视图时出现错误,我不理解代码中的错误。我有印刷品和实物吗?怎么解决呢 这是我的控制器:Php 打印视图时的htmlspecialchars(),php,laravel,Php,Laravel,我得到一个错误: htmlspecialchars()要求参数1为字符串,对象为给定值 当打印视图时出现错误,我不理解代码中的错误。我有印刷品和实物吗?怎么解决呢 这是我的控制器: foreach($asesorias as $asesoria) { $asesoriasWithNames = Array ( 'comunidad' => Comunidad::getNameComunidad($asesoria-&g
foreach($asesorias as $asesoria)
{
$asesoriasWithNames = Array
(
'comunidad' => Comunidad::getNameComunidad($asesoria->comunidad_id),
'provincia' => Provincia::getProvinciaName($asesoria->provincia_id),
'municipio' => Municipio::getMunicipioName($asesoria->municipio_id),
'place' => $asesoria->place,
'date' => $asesoria->date,
'time' => $asesoria->time,
);
}
//dd($asesoriasWithNames);
return view('procesar',compact('marker','asesoriasWithNames'));
我的看法是:
@foreach($asesoriasWithNames as $key => $value)
@if($loop->index % 4 == 0)
<div class="card-deck">
@endif
<div class="card mb-3">
<img src="/adminlte/img/user4-128x128.jpg" class="card-img-top" alt="...">
<div class="card-body">
<p class="card-text">
<strong>$key: </strong>{{ $value }}<br>
<p class="card-text text-center" style="position:absolute;bottom: 0;left: 0;right: 0;">
<a href="#" class="btn btn-info">Reservar</a>
</p>
</div>
</div>
@if($loop->iteration % 4 == 0)
</div>
@endif
@endforeach
我将函数更改为只返回字符串而不是对象 之前:
public static function getNameComunidad($id)
{
return DB::table('comunidades')
->where('id', '=', $id)
->first();
}
已更改:
public static function getNameComunidad($id)
{
return DB::table('comunidades')
->where('id', '=', $id)
->first()->comunidad;
}
我将函数更改为只返回字符串而不是对象 之前:
public static function getNameComunidad($id)
{
return DB::table('comunidades')
->where('id', '=', $id)
->first();
}
已更改:
public static function getNameComunidad($id)
{
return DB::table('comunidades')
->where('id', '=', $id)
->first()->comunidad;
}
在
$key=>$value
的前3次迭代中,无法打印$value
,因为它是一个对象。您需要在循环中添加一些逻辑来打印{{{$value->comunidad}
,{{{$value->provincia}
和{{$value->municipio}
。可能检查get_class($value)
,或者其他一些东西。我怎么能只获取字符串和对象,我已经尝试过了,但返回null:public静态函数getNameComunidad($id){$name=DB::table('comunidades')->where('id','=','id'))->value('comunidad');}$name=DB::table('comunidades')->其中('id','=',$id)->first()->comunidad
。我以前没有见过->value()
调用,但是first()->{attribute}
应该适合您。谢谢,但是我得到了null值。我现在不知道为什么。我测试了$name=DB::table('comunidades')->其中('id','=',$id)->first()->comunidades仍然可以是null
->first()
不保证返回值。将3个功能的内容张贴到您的问题中;可能有助于我们进行调试。在$key=>$value
的前3次迭代中,您无法打印$value
,因为它是一个对象。您需要在循环中添加一些逻辑来打印{{{$value->comunidad}
,{{{$value->provincia}
和{{$value->municipio}
。可能检查get_class($value)
,或者其他一些东西。我怎么能只获取字符串和对象,我已经尝试过了,但返回null:public静态函数getNameComunidad($id){$name=DB::table('comunidades')->where('id','=','id'))->value('comunidad');}$name=DB::table('comunidades')->其中('id','=',$id)->first()->comunidad
。我以前没有见过->value()
调用,但是first()->{attribute}
应该适合您。谢谢,但是我得到了null值。我现在不知道为什么。我测试了$name=DB::table('comunidades')->其中('id','=',$id)->first()->comunidades仍然可以是null
->first()
不保证返回值。将3个功能的内容张贴到您的问题中;可能会帮助我们调试。