cyberhorse / metabase-php

此包已被废弃,不再维护。作者建议使用 ipeevski/metabase-php 包。

嵌入 Metabase

0.3.0 2023-05-12 16:55 UTC

This package is auto-updated.

Last update: 2023-05-18 02:17:12 UTC


README

嵌入 Metabase 框架的库

安装

  • 通过 composer 安装 composer require ipeevski/metabase-php
  • 前往 Metabase 并启用嵌入 - https://[metabase_url]/admin/settings/embedding_in_other_applications
  • 记录 Metabase 基础 URL 和嵌入密钥

使用

基本使用

首先,您需要找到要嵌入的仪表板或问题。记录其 ID - 它将在 URL 的末尾(例如 https://[metabase_url]/dashboard/1?date=past26weeks

注意 /dashboard/ 后的整数 - 那是仪表板的 ID。还要注意 URL 末尾的 GET 参数 - 这些可能是您想要传递给仪表板的其他参数。

<?php
include 'vendor/autoload.php';

// The url of the metabase installation
$metabaseUrl = '[metabase_url]';
// The secret embed key from the admin settings screen
$metabaseKey = '[metabase_key]';
// The id of the dashboard (from the url)
$dashboardId = 1;
// Any parameters to pass to the dashboard
$params = ['date' => 'past26weeks'];

$metabase = new \Metabase\Embed($metabaseUrl, $metabaseKey);
// Generate the HTML to create an iframe with the embedded dashboard
echo $metabase->dashboardIframe($dashboardId, $params);