【问题标题】:cakephp Image Links with class associatedcakephp 图片链接与相关的类
【发布时间】:2014-06-03 10:43:19
【问题描述】:

使用 Cakephp html 助手,我如何在蛋糕中做到这一点?

<a class="logo" href="index.php">
 <img src="img/logo.png">
</a>

我这样做了:

echo $this->Html->image("logo.png", array( 
    "alt" => "Logo", 
    "class" => "logo", 
    'url' => array( 
        'controller' => 'Home', 
        'action' => 'index'
    )
));

这将执行此 html 代码:

<a href="/Root/Home/index/">
<img class='logo' alt="ArtBid Logo" src="/artbid/img/logo.png">
</a>

但是“logo”类转到 img 而不是应该的锚点。

【问题讨论】:

    标签: php cakephp html-helper


    【解决方案1】:

    您应该在图像周围使用$this-&gt;Html-&gt;link() 并在其中设置类。

    echo $this->Html->link(
        $this->Html->image("logo.png", array( 
            "alt" => "Logo"
        )),  
        array("controller" => "Home", "action" => "index"),
        array("class" => "logo", "escape" => false) 
    );
    

    【讨论】:

    • 我试过你的代码,但它不起作用,你的意思是:echo $this->Html->link($this->Html->image("logo.png", array( "alt" => "Logo")),array("class" => "logo","url" => array("controller" => "Home", "action" => "index")));
    • 有些东西不工作:/root/dir1/
    • 尝试在类数组后面加上array('escape' =&gt; false)
    【解决方案2】:
    echo $this->Html->link($this->Html->image('image.jpg', ['class' => 'imgClass']), ['controller' => 'contents', 'action' => 'home'], ['escape' => false, 'class' => 'linkClass']);
    

    【讨论】:

      猜你喜欢
      • 2011-02-16
      • 1970-01-01
      • 2011-03-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-02
      相关资源
      最近更新 更多