簡體   English   中英

cakephp:如何在cakephp中編寫此鏈接

[英]cakephp : How can i write this link in cakephp

<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
                                                                                )
                                                                            );
?>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM