2017-02-16 4 views
0

URL、高さ、幅などからiframeを書式設定しようとしています。ここに私がこれまで持っていたコードがあります。連想配列からのURLの書式設定

   <div class="row" 
        <div class="col-md-6"> 
         <div class="info-box twitter-bg"> 
          <div> 
           <?php 
           if ($cfg_array['grafana'] == 'true') { 
            include 'dashlets.php'; 
            foreach ($dl as $element) { 
             $url = $element["url"]; 
             $height = $element["height"]; 
             $width = $element["width"]; 
             echo "<iframe src=\"" . $url . " \"" . "height=\"" . $height . " \"" . "width=\"" . $width . " \"" . "frameborder=\"0\">" . " " . "<\iframe>" . " "; 
            } 
           } 
           ?> 
          </div> 
         </div> 
        </div> 

ここは、dashlets.phpの配列です。

<?php 
$dl = array(
    'dashlet1' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=6', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet2' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=7', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet3' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=11', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet4' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=4', 
     'height' => '200', 
     'width' => '350' 
    ), 
    'dashlet5' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=8', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet6' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=10', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet7' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=3', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet8' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=5', 
     'height' => '200', 
     'width' => '350' 
    ) 
); 

私の問題は、いつループと最後の値内部以下に示すように、そのループブラケットの外側に配置されている場合、ループのみ配列から最初の値のいずれかを引くことです。 複数ののURLを配列アイテムからフォーマットし、それらを相互に水平なiframeに配置しようとしています。 私が間違っていることはありますか?

html divを含む完全なコードを追加するように編集されました。

すべてをdashlets.phpに移動しました。私はまだ最初の配列項目から返された結果しか得ていません。

<?php 

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 
$dl = array(
    'dashlet1' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=6', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet2' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=7', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet3' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=11', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet4' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=4', 
     'height' => '200', 
     'width' => '350' 
    ), 
    'dashlet5' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=8', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet6' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=10', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet7' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=3', 
     'height' => '200', 
     'width' => '450' 
    ), 
    'dashlet8' => array(
     'url' => 'http://192.168.86.105:3000/dashboard-solo/db/home?panelId=5', 
     'height' => '200', 
     'width' => '350' 
    ) 
); 
foreach ($dl as $element) { 
    $url = $element["url"]; 
    $height = $element["height"]; 
    $width = $element["width"]; 
    echo "<iframe src=\"" . $url . "\"" . " height=\"" . $height . "\" " . "width=\"" . $width . "\"" . " frameborder=\"0\">" . " " . "<\iframe>" . "\n"; 
} 

私のmain.phpでは、私のindex.phpビューポートから見ることができます。

<?php 
     $dl = array(
      'dashlet1' => array(
       'url' => 'http://1.1.1.1:3333/stuff/stuff?36', 
       'height' => '200', 
       'width' => '450' 
      ), 
      'dashlet2' => array(
       'url' => 'http://1.1.1.1:3333/stuff/stuff?37', 
       'height' => '200', 
       'width' => '450' 
       ...... 
       ...... 
       'width' => '450' 
      ), 
      'dashlet8' =>array(
      'url' => 'http://1.1.1.1:3333/stuff/stuff?35', 
      'height' => '200', 
      'width' => '350' 
      ) 
      ); 
    ?> 

そして、ループ内でエコーを置く:

  <div class="row" 
       <div class="col-md-6"> 
        <div class="info-box twitter-bg"> 
         <div> 
          <?php 
          if ($cfg_array['grafana'] == 'true') { 
           include 'dashlets.php'; 

          } 
           ?> 
          </div> 
         </div> 
        </div> 
+0

PHPコードの結果はどうですか? –

答えて

1

私はちょうどdashlets.php中に加え、あなたのコードを試してみてください

include 'dashlets.php'; 
    foreach ($dl as $element) { 
     $url = $element["url"]; 
     $height = $element["height"]; 
     $width = $element["width"]; 
     echo "<iframe src=\"" . $url . "\"" . " height=\"" . $height . "\" " . "width=\"" . $width . "\"" . " frameborder=\"0\">" . " " . "<\iframe>" . "\n"; 
    } 

そして、この得た:

<iframe src="http://1.1.1.1:3333/stuff/stuff?36" height="200" width="450" frameborder="0"> <\iframe> 
<iframe src="http://1.1.1.1:3333/stuff/stuff?37" height="200" width="450" frameborder="0"> <\iframe> 
<iframe src="http://1.1.1.1:3333/stuff/stuff?311" height="200" width="450" frameborder="0"> <\iframe> 
<iframe src="http://1.1.1.1:3333/stuff/stuff?34" height="200" width="350" frameborder="0"> <\iframe> 
<iframe src="http://1.1.1.1:3333/stuff/stuff?38" height="200" width="450" frameborder="0"> <\iframe> 
<iframe src="http://1.1.1.1:3333/stuff/stuff?310" height="200" width="450" frameborder="0"> <\iframe> 
<iframe src="http://1.1.1.1:3333/stuff/stuff?33" height="200" width="450" frameborder="0"> <\iframe> 
<iframe src="http://1.1.1.1:3333/stuff/stuff?35" height="200" width="350" frameborder="0"> <\iframe> 
+0

私が述べたように、私はそれを試して、配列にリストされている最初の値以上のものは何も生成しませんでした。 –

+0

Dashlets.phpにはがありますか? –

+0

はい、私は最初に<?phpを持っていますが、その中に配列だけがあるので、ファイルを閉じることはありませんか? orignal投稿を更新して、そのdivのすべてを反映させました。私はまた、混乱がないことを確実にするためにループ内にあるようにechoステートメントを移動しました。 –