image() public method

This method will set an empty alt attribute if one is not supplied. ### Usage: Create a regular image: echo $this->Html->image('cake_icon.png', ['alt' => 'CakePHP']); Create an image link: echo $this->Html->image('cake_icon.png', ['alt' => 'CakePHP', 'url' => 'http://cakephp.org']); ### Options: - url If provided an image link will be generated and the link will point at $options['url']. - fullBase If true the src attribute will get a full address for the image file. - plugin False value will prevent parsing path as a plugin
public image ( string $path, array $options = [] ) : string
$path string Path to the image file, relative to the app/webroot/img/ directory.
$options array Array of HTML attributes. See above for special options.
return string completed img tag
Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function image($path, array $options = array())
 {
     if ('text' == $this->getType()) {
         return null;
     }
     return parent::image($path, $this->_mergeAttributes($options, $this->config('attributes.image')));
 }
 /**
  * Overloaded Html->image() method
  * change image src for using AdaptiveImages plugin
  *
  * @param string $path Path to the image file, relative to the app/webroot/img/ directory.
  * @param array $options Array of HTML attributes. See above for special options.
  * @return string completed img tag with chenged src
  */
 public function image($path, array $options = [])
 {
     // if ($path[0] == '/') { //absolute
     //     $path = substr($path, 1);
     //     $file = new File(WWW_ROOT . $path);
     // } else { //relative
     //     $file = new File(WWW_ROOT . 'img' . DS . $path);
     // }
     // return dirname($file->path);
     if ($path[0] != '/') {
         $path = '/img/' . $path;
     }
     $path = '/adaptive_images' . '?path=' . $path;
     if (isset($options['semanticType'])) {
         $path .= '&semanticType=' . $options['semanticType'];
     }
     return parent::image($path, $options);
 }
Ejemplo n.º 3
0
 /**
  * Creates a formatted `<img>` element
  * @param string $path Path to the image file, relative to the
  *  `APP/webroot/img/` directory
  * @param array $options Array of options and HTML attributes
  * @return string
  */
 public function image($path, array $options = [])
 {
     $options = $this->optionsDefaults(['alt' => pathinfo($path, PATHINFO_BASENAME)], $options);
     $options = $this->optionsValues(['class' => 'img-responsive'], $options);
     $options = $this->addTooltip($options);
     return parent::image($path, $options);
 }