Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/286.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 在Laravel和ViewMore按钮中创建单个产品信息页面_Php_Laravel 4 - Fatal编程技术网

Php 在Laravel和ViewMore按钮中创建单个产品信息页面

Php 在Laravel和ViewMore按钮中创建单个产品信息页面,php,laravel-4,Php,Laravel 4,在Laravel和框架方面真的很新,所以请接受我的建议。我正在努力学习它,我选择写一些产品(标题、价格、图片、描述)的简单索引页面。到目前为止,一切都在那里。现在,我正试图将ViewMore按钮放在“说明”部分,当我点击按钮向我加载包含该产品更多信息的新页面时 这是索引页面的视图,我在其中显示所有产品,并希望使按钮视图更 @if($product['image']) <img class="max-150" src="{{ $product['image'] }}" alt="{{

在Laravel和框架方面真的很新,所以请接受我的建议。我正在努力学习它,我选择写一些产品(标题、价格、图片、描述)的简单索引页面。到目前为止,一切都在那里。现在,我正试图将
ViewMore
按钮放在“说明”部分,当我点击按钮向我加载包含该产品更多信息的新页面时

这是索引页面的视图,我在其中显示所有产品,并希望使按钮视图更

@if($product['image'])
    <img class="max-150" src="{{ $product['image'] }}" alt="{{{ $product['title'] }}}" />
     <br /><br />
@endif
@if($product['description_small'])
     <p>{{ $product['description_small'] }}</p>
     <p>{{ str_limit($product['description_small'], $limit = 250, $end = '<br><br> <a href="{{ URL::to('/product/single/' . $product['product_id']) }}" class="btn btn-primary">View More</a>') }}</p> 
@endif
@if($product['image']))


@恩迪夫 @如果($product['description_small'])) {{$product['description_small']}

{{str_limit($product['description_small'],$limit=250,$end='

')}

@恩迪夫
现在我在视图链接中遇到了更多错误,错误是

production.ERROR:异常“Symfony\Component\Debug\exception\FatalErrorException”,消息“语法错误,意外的”product\u id'(T\u字符串)“

当我只使用a href时,它工作得很好

 <p><br><br> <a href="{{ URL::to('/product/single/' . $product['product_id']) }}" class="btn btn-primary">View More</a></p>



您在一个echo(
{{{{}}}
)中进行echo'ing

这项工作:

{{ str_limit($product['description_small'], $limit = 250, $end = '<br><br><a href="' . URL::to('/product/single/' . $product['product_id']) . '" class="btn btn-primary">View More</a>') }}
{{str_limit($product['description_small'],$limit=250,$end='

')}
虽然我觉得这段代码有点草率,难以阅读,但一种更简洁的方法是:

$button = sprintf('<a href="%s" class="btn btn-primary view-more">View More</a>', URL::to('product/single/' . $product['product_id']));

echo str_limit($product['description_small'], 250, $button);
$button=sprintf(“”,URL::to('product/single/')。$product['product_id']);
echo str_limit($product['description_small',250,$button);
。。。或者类似(我最喜欢的):

{{str_limit($product->description,250)}
@如果(strlen($product->description)>250)
@恩迪夫

不要使用那些讨厌的内联

标记,样式设置
.btn。使用一些CSS查看更多
将达到效果:)

我认为您添加的这段代码不会触发语法错误。另一方面:为什么产品是阵列?使用雄辩的:)编辑:我发现了语法错误,用一个尖刻的答案回答了这个。。当链接类似于:
{stru-limit($product['description\u-small'],$limit=250,$end='

')}
时,它会抛出此错误。。但是如果我这样做,没有问题,但是我没有得到答案。这真的帮了我的忙!我已经实现了你最喜欢的方式。我只是有个问题。可以不删掉这样的词吗?:)是的,检查这个问题
{{ str_limit($product->description, 250) }}

@if (strlen($product->description) > 250)
    <a href="{{ URL::to('product/single/' . $product->id) }} " class="btn btn-primary view-more">View More</a>
@endif