简体   繁体   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>

in using pagination i need to convert this link in cakephp way because on other page of pagination this html <a href=""></a> will not work. 在使用分页时,我需要以cakephp的方式转换此链接,因为在分页的其他页面上,此html <a href=""></a>无效。

And this is my all code of that .ctp file 这是我所有的.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
}
?>

your question is little confusing. 您的问题有点令人困惑。 Still considering 'Public' as 'Controller' and 'singleproduct' as 'action' , you can write this way : 仍然将“公共”视为“控制器”,并将“单一产品”视为“动作”,您可以这样编写:

<?php echo $this->Html->link('link text here', array(
'controller' => 'Public',
'action' => 'singleproduct',
'?' => array('id' => $row["Product"]["id"]))
); ?>

i tried this and it's working for me.Posting answer just because may be it can help someone. 我试过了,它对我有用。发布答案只是因为它可以帮助某人。

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