Html::image PHP Method

image() static public method

This method will set an empty alt attribute if no alt and no title is not supplied
static public image ( $path, $options = [] ) : string
$path Path to the image file
$options Array of HTML attributes - `url` If provided an image link will be generated and the link will point at `$options['url']`.
return string completed img tag
    static function image($path, $options = array())
    {
        if (!isset($options['title'])) {
            $options['title'] = '';
        }
        if (!isset($options['alt'])) {
            $options['alt'] = $options['title'];
        }
        if (empty($options['title']) && !empty($options['alt'])) {
            $options['title'] = $options['alt'];
        }
        $url = false;
        if (!empty($options['url'])) {
            $url = $options['url'];
            unset($options['url']);
        }
        $class = "";
        if ($url) {
            $class = "class='pointer'";
        }
        $image = sprintf('<img src="%1$s" %2$s %3$s />', $path, Html::parseAttributes($options), $class);
        if ($url) {
            return Html::link($image, $url);
        }
        return $image;
    }

Usage Example

コード例 #1
0
 public function overviewImage()
 {
     if (!$this->isNewRecord) {
         if ($this->hasIcon()) {
             return Html::image('/uploads/' . $this->icon_file, $this->name);
         }
     }
 }
All Usage Examples Of Html::image
Html