问题
I have the below code in my app. The problem is the @ (at sign). When it's there, I get syntax highlighting and errors as if the string doesn't end. When remove it, the page works fine (minus the action not existing). I've tried escaping the @ and that doesn't work. I've also tried double quotes, but that doesn't work either. How can I escape @?
I could use the route function and avoid the @ entirely but I feel that the action function is far more clear in terms of what it's doing so I'd rather not use route.
@extends('layouts.default') <?php
$url = URL::action('UsersController@index'); ?>
@section('header')
@include('partials.components.searchHeader', array('title' => "Users", 'results' => $users->getTotal(), 'total' => $total, 'url' => URL::route( 'users.index' ), 'type' => 'user'))
@stop
<?php
if(Auth::user()->isAdmin()) $publishedFellows = Fellow::published()->get();
if(!Auth::user()->isFellow()) $publishedOpportunities = Opportunity::select('opportunities.*')->published()->sortedByCompany()->get(); ?>
@section('content')
@if(Auth::user()->isAdmin())
@include('partials.components.add-button', array('url' => '/users/create', 'name' => 'Add User'))
@endif
<?php $partialsList = [
'listItems' => $users,
'search' => $search,
'url' => URL::route('users.index'),
'pills' => $pills,
'indexView' => 'users.single',
'type' => 'user',
'total' => $total,
]; ?>
@include('partials.list')
@stop
回答1:
To escape @
symbols in blade - you just use a double @@
.
So this:
@@example
will print
@example
However your code is very messy, and that is probably causing you problems. The biggest issue is you are using extend
- but then you are putting code inbetween the sections, which is not called correctly. Further - the code you are putting inbetween the sections to save variables is not even been called anywhere!
You should refactor your view to something like this to fix the issue:
@extends('layouts.default')
@section('header')
@include('partials.components.searchHeader', ['title' => "Users", 'results' => $users->getTotal(), 'total' => $total, 'url' => URL::route( 'users.index' ), 'type' => 'user'])
@stop
@section('content')
@if(Auth::user()->isAdmin())
@include('partials.components.add-button', ['url' => '/users/create', 'name' => 'Add User'])
@endif
@include('partials.list', ['listItems' => $users, 'search' => $search, 'url' => URL::route('users.index'), 'pills' => $pills, 'indexView' => 'users.single', 'type' => 'user', 'total' => $total])
@stop
来源:https://stackoverflow.com/questions/29450708/using-at-sign-in-php-laravel-strings