riipandi / php-metabase
在您的PHP应用程序中嵌入Metabase
v1.2
2021-12-22 22:02 UTC
Requires
- lcobucci/jwt: ^4.0
This package is auto-updated.
Last update: 2024-08-29 05:41:30 UTC
README
库用于嵌入 Metabase 框架。从 ipeevski/metabase-php 分支
安装
- 通过composer安装:
composer require riipandi/php-metabase
- 前往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'; $metabaseUrl = '[metabase_url]'; // The url of the metabase installation $metabaseKey = '[metabase_key]'; // The metabase secret embed key $dashboardId = 1; // The id of the dashboard (from the url) $params = ['date' => 'past26weeks']; // Any parameters to pass to the dashboard (optional) $metabase = new \Metabase\Embed($metabaseUrl, $metabaseKey); // Generate the HTML to create an iframe with the embedded dashboard echo $metabase->dashboardIframe($dashboardId, $params);
使用Laravel
在 config/metabase.php
创建配置文件
<?php return [ 'url' => env('METABASE_URL', 'https://:3000'), 'key' => env('METABASE_KEY'), ]
<?php $metabaseUrl = config('metabase.url'); // The url of the metabase installation $metabaseKey = config('metabase.key'); // The metabase secret embed key $dashboardId = 1; // The id of the dashboard (from the url) $params = ['date' => 'past26weeks']; // Any parameters to pass to the dashboard (optional) $metabase = new \Metabase\Embed($metabaseUrl, $metabaseKey); // Generate the HTML to create an iframe with the embedded dashboard echo $metabase->dashboardIframe($dashboardId, $params);