Laravel 5 Pagination CSS Breaking

我正在使用Laravel 5和Bootstrap 3.3.4 </ p>

所以我 在我的控制器中有以下代码:</ p>

  $ articles = Newsarticles :: paginate(10); 
return view('news',compact('articles');
</ code> </ pre>

然后在我看来,我有:</ p>

  @foreach($ articles as $ article)

&lt; article&gt;
&lt; h2&gt;
&lt; a href =“{!! action('DynamicPages @ show',[$ article-&gt; slug])!!}”&gt; {!! $ article-&gt; 标题!!}&lt; / a&gt;
&lt; / h2&gt;
&lt; div class =“body”&gt;
{!! substr($ article-&gt; article,0,500)!!}
&lt ; / div&gt;
&lt; / article&gt;

@ endforeach

{!! $ articles-&gt; render()!!}
</ code> </ pre>

当我运行它时,页面底部的分页链接就好了,看起来应该如此。但是,如果我将控制器更改为:</ p>

  $  articles = Newsarticles :: orderBy('artdate','DESC') - &gt; paginate(10); 
</ code> </ pre>

我的分页链接就像 这样的:</ p>

«结果,\ N1结果\ N2结果\ N3结果\ N4结果\ N5结果\ N6结果
» </ p>

代码中的一个小调整如何打破css?</ p>
</ div>

展开原文

原文

I'm using Laravel 5 and Bootstrap 3.3.4

So I have the following code in my controller:

$articles = Newsarticles::paginate(10);
return view ('news',compact('articles');

Then in my view I have:

@foreach($articles as $article)

<article>
    <h2>
        <a href="{!! action('DynamicPages@show', [$article->slug]) !!}">{!! $article->headline !!}</a>
    </h2>
    <div class="body">
        {!! substr($article->article,0,500) !!}
    </div>
</article>

@endforeach

{!! $articles->render() !!}

When I run this, the pagination links at the bottom of the page come out just fine and look as they should do. However, if I change the controller to :

$articles = Newsarticles::orderBy('artdate','DESC')->paginate(10);

my pagination links come out like this:

«
1
2
3
4
5
6
»

How can one small adjustment in the code break the css?

douan6931
douan6931 别客气。我刚发布了我的答案:)
5 年多之前 回复
dongqiu3254
dongqiu3254 先生,你是天才!谢谢@minioz!!!
5 年多之前 回复
dsfds2343
dsfds2343 我想,你允许用户在$article->title或$article->article中输入html标签。因此,您可能在$article->headline或$article->article中有一个损坏的标记。您可以通过删除这些行并刷新页面来测试它。
5 年多之前 回复

4个回答



使用substr($ article-&gt; article,0,500)你可能会破解html代码。</ p>

你也可以拥有不同数量的生命字符</ p>

p&gt; hello&lt; / p&gt; </ code> </ p>

12个字符< / p>

&lt; stong&gt; hello&lt; / strong&gt; </ code> </ p>

21个字符。</ p>

并注意这一点:</ p>

  echo substring('&lt; p&gt; hello&lt; / p&gt;',5); 
</ code> </ pre> \ n

写道:“</ p>

他”。 Breack html结果。</ p>

尝试</ p>

substr(strip_tags($ article-&gt; article,0,500))</ code> < / p>

在剪切字符串之前删除所有html选项卡。 这不会破坏你当前的html,你将获得正确的字符长度。</ p>
</ div>

展开原文

原文

With substr($article->article,0,500) you may breack html code.

You can also have a distinct number of vivible chars

p>hello</p>

12 chars

<stong>hello</strong>

21 chars.

And take care of this:

echo substring('<p>hello</p>', 5);

Writes: "

he". Breack html result.

Try with

substr(strip_tags($article->article,0,500))

to strip all html tabs before cut the string. This will not breack your current html and you will get the correct chars length.



来自我上面的评论。</ p>

问题是破解的html标记。 这是因为在这一行使用了substr()。</ p>

  {!!  substr($ article-&gt; article,0,500)!!} 
</ code> </ pre>

该函数将删除部分 $ article-&gt;文章</ 代码>并打开一些标签。</ p>

要解决问题,您需要在执行substr()</ p>

  {!!之前删除标签 substr(strip_tags($ article-&gt; article),0,500)!!} 
</ code> </ pre>
</ div>

展开原文

原文

From my comment above.

The problem was the broken html tag. It is because of using substr() at this line.

{!! substr($article->article,0,500) !!}

The function will cut out part of the $article->article and left some tags open.

To solve to problem you need to remove tags before do substr()

{!! substr(strip_tags($article->article),0,500) !!}



没有转义标签,打开的HTML标签正在杀掉css。 感谢@minioz将其指出</ p>
</ div>

展开原文

原文

Hadn't escaped tags and an open HTML tag was killing off the css. Thanks to @minioz for pointing it out



没有足够的信息可以回答 - 但三大可能性是</ p>


  1. 不知何故,你在每个例子中呈现不同的HTML </ p> </ li>

  2. 页面上的其他CSS不是防弹的,它正在创建不同的容器包装 基于标题和内容长度</ p> </ li>

  3. $ article-&gt; article </ code>, $ article-&gt; slug <中有HTML内容 / code>,或 $ article-&gt;标题</ code>,其中包含打开布局的未关闭标签(或干扰页面CSS的意外标签/样式/类)</ p> </ li>
    </ ol>

    制作不同请求页面的原始页面源(View - &gt; Developer - &gt; View Source in Chrome)的副本,然后通过diff程序运行(CLI diff </ code>,WinMerge, opendiff </ code>等)以发现任何渲染差异。</ p>

    假设没有,请调查每个内容区域 对于破碎的标签,然后启动popu 使用不同的长度标题和文本正文区域布局您的布局,直到您触发问题,然后从那里修复您的CSS。 </ p>

    祝你好运!</ p>
    </ div>

展开原文

原文

Not enough information to answer -- but the three big possibilities are

  1. Somehow you're rendering different HTML in each example

  2. Other CSS you have on the page isn't bullet-proof, and it's creating different container wraps based on headline and content length

  3. There's HTML content in $article->article, $article->slug, or $article->headline with unclosed tags that's breaking the layout (or unexpected tags/styles/classes that interfere with the page CSS)

Make a copy of the raw page source (View -> Developer -> View Source in Chrome) of the page for the different requests and then run through through a diff program (CLI diff, WinMerge, opendiff, etc.) to spot any rendering differences.

Assuming there's none, investigate each but of content area for broken tags, and then start populating your layout with different length headlines and text body area until you trigger the issue, and then fix your CSS from there.

Good luck!

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐