superbig/craft-airtable

该包已被废弃,不再维护。未建议替代包。

使用Airtable轻松保存和获取数据

安装: 7

依赖: 0

建议者: 0

安全: 0

星星: 5

关注者: 3

分支: 0

开放问题: 2

类型:craft-plugin

dev-master 2019-09-04 19:27 UTC

This package is auto-updated.

Last update: 2024-05-15 09:24:29 UTC


README

使用Airtable轻松保存和获取数据

Screenshot

要求

此插件需要Craft CMS 3.0.0-beta.23或更高版本。

安装

要安装此插件,请按照以下说明操作。

  1. 打开您的终端并转到您的Craft项目

     cd /path/to/project
    
  2. 然后告诉Composer加载插件

     composer require superbig/craft-airtable
    
  3. 在控制面板中,转到设置→插件,并点击Airtable的“安装”按钮。

Airtable概览

Airtable是一种人性化的数据库解决方案,使得管理和处理简单和复杂的关系数据变得极其简单。

配置Airtable

<?php
return [
    // Find this on https://airtable.com/account
    'apiKey'        => '',

    // Find this on https://airtable.com/api
    'base'
                    => '',
    // The name of the default table. Make sure the capitalization is correct
    'defaultTable'         => '',

    // Allowed field keys per table. This matches the field names in the table
    'allowedFields' => [ ],
];

使用Airtable

要从表中获取记录

{% set records = craft.airtable.records.table('contacts').find() %}

更改基础表

{% set records = craft.airtable.records.base('appvv0LuV2oP5AsS').table('Equipment').find() %}

示例表单

<form method="post" accept-charset="UTF-8">
    {{ csrfInput() }}
    {{ redirectInput('airtable?success={Name}') }}
    <input type="hidden" name="action" value="airtable/save">
    <input type="hidden" name="table" value="{{ 'Content'|hash }}">
    <input type="hidden" name="enabled" value="1">

    {% macro errorList(errors) %}
        {% if errors %}
            <ul class="errors">
                {% for error in errors %}
                    <li>{{ error }}</li>
                {% endfor %}
            </ul>
        {% endif %}
    {% endmacro %}

    {% from _self import errorList %}

    {# Display server error #}
    {% if airtable is defined %}
        {{ errorList(airtable.getErrors('server')) }}
    {% endif %}

    <label for="name">Name</label>
    <input id="name" type="text" name="Name"
            {%- if airtable is defined %} value="{{ airtable.Name }}"{% endif -%}>

    {% if airtable is defined %}
        {{ errorList(airtable.getErrors('Name')) }}
    {% endif %}

    <label for="email">E-mail</label>
    <input id="email" type="text" name="E-mail"
            {%- if airtable is defined %} value="{{ airtable['E-mail'] }}"{% endif -%}>

    {% if airtable is defined %}
        {{ errorList(airtable.getErrors('E-mail')) }}
    {% endif %}

    <label for="notes">Notes</label>
    <textarea id="notes" name="Notes">
        {%- if airtable is defined %}{{ airtable.Notes }}{% endif -%}
    </textarea>

    {% if airtable is defined %}
        {{ errorList(airtable.getErrors('Notes')) }}
    {% endif %}

    <fieldset>
        {% set options = ['First option', 'Second option'] %}
        {% for option in options %}
            <label>
                <input type="radio" name="Single-select" value="{{ option }}"
                        {%- if airtable is defined and airtable['Single-select'] == option %} checked{% endif -%}>
                {{ option }}
            </label>
        {% endfor %}
    </fieldset>

    {% if airtable is defined %}
        {{ errorList(airtable.getErrors('Single-sele{ct')) }}
    {% endif %}

    <fieldset>
        {% set options = ['First option', 'Second option'] %}
        {% for option in options %}
            <label>
                <input type="checkbox" name="Multi-select[]" value="{{ option }}"
                        {%- if airtable is defined and option in airtable['Multi-select'] %} checked{% endif -%}>
                {{ option }}
            </label>
        {% endfor %}
    </fieldset>

    {% if airtable is defined %}
        {{ errorList(airtable.getErrors('Multi-select')) }}
    {% endif %}

    <fieldset>
        <label for="date">Date</label>
        <input id="date" type="date" name="Date"
                {%- if airtable is defined %} value="{{ airtable['Date'] }}"{% endif -%}>
    </fieldset>

    {% if airtable is defined %}
        {{ errorList(airtable.getErrors('Date')) }}
    {% endif %}

    <label>
        <input type="checkbox" name="Checkbox" value="1"
                {%- if airtable is defined and airtable['Checkbox'] %} checked{% endif -%}>
        Accept terms
    </label>

    {% if airtable is defined %}
        {{ errorList(airtable.getErrors('Checkbox')) }}
    {% endif %}

    <input type="submit" value="Save">
</form>

在表中查找记录

{% set records = craft.airtable.records.table('contacts').find() %}
{% if records.getData() | length %}
    <table>
        <thead>
        <tr>
            <th>Name</th>
            <th>E-mail</th>
            <th>Date</th>
        </tr>
        </thead>
    {% for record in records.getData() %}
        <tr>
            <td>{{ record['Name']|default('') }}</td>
            <td>{{ record['E-mail']|default('') }}</td>
            <td>{{ record['Date']|default('') }}</td>
        </tr>
    {% endfor %}
    </table>
{% endif %}

根据条件在表中查找记录

{% set records = craft.airtable.records.table('contacts').find({
    'Name': 'Thomas'
}) %}
{% if records.getData() | length %}
    <table>
        <thead>
        <tr>
            <th>Name</th>
            <th>E-mail</th>
            <th>Date</th>
        </tr>
        </thead>
        {% for record in records.getData()  %}
            <tr>
                <td>{{ record['Name']|default('') }}</td>
                <td>{{ record['E-mail']|default('') }}</td>
                <td>{{ record['Date']|default('') }}</td>
            </tr>
        {% endfor %}
    </table>
{% endif %}

Airtable路线图

一些要完成的事情以及潜在功能的想法

  • 支持附件
  • 添加日志
  • 缓存

Superbig提供