php 如何使用 Bootstrap 在 CakePHP 模板文件 (default.ctp) 上显示图像

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18416246/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 17:30:57  来源:igfitidea点击:

How to display Images on CakePHP template file (default.ctp) Using Bootstrap

phpcakephptwitter-bootstraptwitter-bootstrap-3

提问by Girish Thimmegowda

I'm creating a Website Dashboard in CakePHP.. And i'm using bootstrap 3.0.

我在 CakePHP 中创建了一个网站仪表板。我正在使用引导程序 3.0。

1) I want to display an image present in webroot/imgin the default.ctpfile.

1)我想在以显示图像本webroot/imgdefault.ctp的文件。

2) I want that image to be displayed inside the thumbnails( bootstrap )div.

2)我希望该图像显示在thumbnails( bootstrap )div 内。

I used html helperie, echo $this->Html->image('img.png', array('alt' => 'CakePHP'));for the sourceattribute of imgtag.

我使用html helperie,echo $this->Html->image('img.png', array('alt' => 'CakePHP'));作为标签的source属性img

but not working..

但不工作..

Edit

编辑

This is how i have tried within bootstrap code.

这就是我在引导代码中尝试的方式。

<div class="row"
    <p><b>Target Image</b></p>
    <div class="col-lg-3 col-md-3 col-sm-3">
         <a href="#" class="thumbnail">
            <img data-src="holder.js/100%x100" src="<?php $this->Html->image('img.png', array('alt' => 'CakePHP', 'border' => '0')); ?>" />
          </a>
     </div>
</div>

回答by Jordi Jolink

Edit:
You are placing a complete image tag into an image's source. See the cookbook's HTML helper for this topic: http://book.cakephp.org/2.0/en/core-libraries/helpers/html.html

编辑:
您将一个完整的图像标签放入图像的源中。请参阅本主题的食谱 HTML 帮助程序:http: //book.cakephp.org/2.0/en/core-libraries/helpers/html.html

So if you replace this line:

因此,如果您替换此行:

<img data-src="holder.js/100%x100" src="<?php $this->Html->image('img.png', array('alt' => 'CakePHP', 'border' => '0')); ?>" />

With this line:

有了这条线:

<?php echo $this->Html->image('img.png', array('alt' => 'CakePHP', 'border' => '0', 'data-src' => 'holder.js/100%x100')); ?>

that should do the trick.

这应该够了吧。

回答by Anil kumar

You can try like this

你可以这样试试

$this->Html->image('img.png', array('alt' => 'CakePHP'));

回答by Daniel Antunes Pinto

In order to make the holder script work properly the src property of the img element should not be setted.

为了使 holder 脚本正常工作,不应设置 img 元素的 src 属性。

So, a propoer solution is:

所以,一个合适的解决方案是:

<?php echo $this->Html->image('', array('alt' => 'CakePHP', 'border' => '0', 'data-src' => 'holder.js/100%x100')); ?>