<a href="../Public/singleproduct?id=<?php echo $row["Product"]["id"];?>">
<div class="single-products">
<div class="productinfo text-center myimg">
<?php echo $this->Html->image("product/".$row["Product"]["photo"]); ?>
<h2>Rs.<?php echo $row["Product"]["price"];?></h2>
<p><?php echo $row["Product"]["name"];?></p>
<a href="javascript:document.ff<?php echo ($i++);?>.submit()" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
<?php echo $this->Session->flash('flash', array('element' => 'flash_notification')); ?>
</div>
</div>
</a>
在使用分页时,我需要以 Cakephp 方式转换此链接,因为在分页的其他页面上,此 HTML <a href=""></a>
将不起作用。
这是我对该.ctp文件的所有代码
<?php
$i=0;
foreach($product as $row)
{
?>
<form name="ff<?php echo $i;?>" method="post">
<input type="hidden" name="product_tbls_id" value="<?php echo $row["Product"]["id"];?>">
<input type="hidden" name="qty" value="1">
<div class="col-sm-4">
<div class="product-image-wrapper">
<a href="../Public/singleproduct?id=<?php echo $row["Product"]["id"];?>">
<div class="single-products">
<div class="productinfo text-center myimg">
<?php echo $this->Html->image("product/".$row["Product"]["photo"]); ?>
<h2>Rs.<?php echo $row["Product"]["price"];?></h2>
<p><?php echo $row["Product"]["name"];?></p>
<a href="javascript:document.ff<?php echo ($i++);?>.submit()" class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>
<?php echo $this->Session->flash('flash', array('element' => 'flash_notification')); ?>
</div>
</div>
</a>
</div>
</div>
</form>
<?php
}
?>
你的问题有点令人困惑。仍然将"公共"视为"控制器",将"单一产品"视为"操作",您可以这样写:
<?php echo $this->Html->link('link text here', array(
'controller' => 'Public',
'action' => 'singleproduct',
'?' => array('id' => $row["Product"]["id"]))
); ?>
我试过这个,它对我有用。发布答案只是因为它可以帮助某人。
<?php
echo $this->Html->link('<div class="single-products">'.'<div class="productinfo text-center myimg">'.$this->Html->image("product/".$row["Product"]["photo"]).'<h2>'.$row["Product"]["price"].'</h2>'.'<p>'.$row["Product"]["name"]."</p><a href='javascript:document.ff".($i++).".submit()' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</a>".$this->Session->flash('flash', array('element' => 'flash_notification')).'</div>'.'</div>',
array
(
'controller'=>'Public',
'action'=>'singleproduct?id='.$row["Product"]["id"],
),
array
(
'escape'=>false
)
);
?>