在 Laravel 4 的视图中使用爆炸

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

Using explode within a view in Laravel 4

phplaravellaravel-4explode

提问by user1072337

I have stored the FBIDs of a Facebook user's friends in a string in a mysql database. The string looks like this:

我已将 Facebook 用户朋友的 FBID 存储在 mysql 数据库中的字符串中。该字符串如下所示:

"fbid1,fbid2,fbid3...etc..."

I am trying to use specific FBIDs in a view (call profile images, for instance). My question is, how do I do this in a Laravel 4 view? I am trying the following:

我正在尝试在视图中使用特定的 FBID(例如,呼叫个人资料图像)。我的问题是,如何在 Laravel 4 视图中执行此操作?我正在尝试以下操作:

array = explode(",", {{ Auth::user()->friend_ids_unpacked}});

However, this just prints out the string with the other portion as text. I know this is incorrect, but I don't know how to perform a php call within the view in Laravel.

但是,这只是将字符串与其他部分一起打印为文本。我知道这是不正确的,但我不知道如何在 Laravel 的视图中执行 php 调用。

Thank you for your help.

感谢您的帮助。

EDIT:

编辑:

Error Log:

错误日志:

Stack trace:
#0 /Applications/MAMP/htdocs/crowdsets/laravel-master/app/storage/views/2ed7fc8952dab08cf4cb4f4e3d40d1ab(119): Illuminate\Exception\Handler->handleError(8, 'Array to string...', '/Applications/M...', 119, Array)
#1 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(9032): include('/Applications/M...')
#2 /Applications/MAMP/htdocs/crowdsets/laravel-master/vendor/laravel/framework/src/Illuminate/View/Engines/CompilerEngine.php(45): Illuminate\View\Engines\PhpEngine->evaluatePath('/Applications/M...', Array)
#3 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(8925): Illuminate\View\Engines\CompilerEngine->get('/Applications/M...', Array)
#4 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(8916): Illuminate\View\View->getContents()
#5 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(9510): Illuminate\View\View->render()
#6 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(9058): Illuminate\Http\Response->setContent(Object(Illuminate\View\View))
#7 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(4921): Symfony\Component\HttpFoundation\Response->__construct(Object(Illuminate\View\View))
#8 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(7811): Illuminate\Routing\Router->prepare(Object(Illuminate\View\View), Object(Illuminate\Http\Request))
#9 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(4762): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#10 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(481): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#11 /Applications/MAMP/htdocs/crowdsets/laravel-master/bootstrap/compiled.php(470): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#12 /Applications/MAMP/htdocs/crowdsets/laravel-master/public/index.php(49): Illuminate\Foundation\Application->run()
#13 {main} [] []

回答by Laurence

You are trying to do two different things. Assuming that you want to get an array of friends - you do this:

您正在尝试做两件不同的事情。假设你想得到一组朋友 - 你这样做:

<? $array = explode(",", Auth::user()->friend_ids_unpacked); ?>

You can then use the array like this:

然后,您可以像这样使用数组:

@foreach ($array as $x)
    <p>This is another id: {{ $x }}</p>
@endforeach

回答by Alexandre Danault

Move your curly braces to fully contain the PHP call:

移动大括号以完全包含 PHP 调用:

{{ $array = explode(",", Auth::user()->friend_ids_unpacked); }}