asImage() public method

Formats the value as an image tag.
public asImage ( mixed $value, array $options = [] ) : string
$value mixed the value to be formatted.
$options array the tag options in terms of name-value pairs. See [[Html::img()]].
return string the formatted result.
Example #1
0
 public function testAsImage()
 {
     $value = 'http://sample.com/img.jpg';
     $this->assertSame("<img src=\"{$value}\" alt=\"\">", $this->formatter->asImage($value));
     // null display
     $this->assertSame($this->formatter->nullDisplay, $this->formatter->asImage(null));
 }
 public function asImage($value, $options = [])
 {
     if ($value === null) {
         return $this->nullDisplay;
     }
     if (empty($value)) {
         if (isset($options['default'])) {
             $value = \Yii::$app->params['domain']['data'] . $options['default'];
             unset($options['default']);
         } else {
             $value = \Yii::$app->params['domain']['data'] . \Yii::$app->params['image']['default']['common'];
         }
     }
     if (!preg_match('/\\b(([\\w-]+:\\/\\/?|www[.])[^\\s()<>]+(?:\\([\\w\\d]+\\)|([^[:punct:]\\s]|\\/)))/i', $value)) {
         $value = \Yii::$app->params['domain']['data'] . $value;
     }
     return parent::asImage($value, $options);
 }