ipeevski/metabase-php

嵌入 Metabase

0.3.0 2023-05-12 16:55 UTC

This package is auto-updated.

Last update: 2024-09-18 05:09:00 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);