Spis treści

SVG

Renderowanie obrazka SVG

Dynamiczne renderowanie pliku SVG w kontrolerze i wysłanie go jako obrazka do tagu IMG

public function actionSvg($id, $ids) {
 
        $elementy = Model::find()
                ->where(['id' => $id])
                ->andWhere(['data' => $ids])
                ->all();      
        $cont = '';
        $cont.= $this->renderPartial('svg', [
            'id' => $id,
            'model' => $elementy,
        ]);
        $response = Yii::$app->getResponse();
        $response->headers->set('Content-Type', 'image/svg+xml');
        $response->format = \yii\web\Response::FORMAT_RAW;
        $response->content= $cont;
        $response->send();
}

Widok svg.php generuje dynamicznie strukturę pliku svg xml

<svg>
 ....
</svg>

W dowolnym widoku:

<img src="/kontroler/svg/2/2017-12-15" alt="">

HTML wewnątrz SVG

Przykład

<html>
<head>
 <meta charset="UTF-8">
 <title>HTML inside SVG</title>
 <style type="text/css"></style></head>
 <body>
 
 <svg width="500" height="300" style="border:1px red solid">
  <foreignobject class="node" x="46" y="22" width="100" height="100">
    <div style="border:1px green solid">
       I'm a div inside a SVG.
    </div> 
  </foreignobject>
 </svg>

 </body>
</html>