//默认是Airtable Connection配置的名称$query = new AirpressQuery("Locations", "default");
$ query = new AirpressQuery(“ Locations”,“ default”);
$query->filterByFormula("{Name}='My Local Pub'");
$ query-> filterByFormula(“ {Name} ='My Local Pub'”);
$locations = new AirpressCollection($query);
$ locations = new AirpressCollection($ query);
$query = new AirpressQuery("Events", "default");
$ query = new AirpressQuery(“ Events”,“ default”);
$query->filterByFormula("IS_BEFORE( TODAY(), {Start Date} )");
$ query-> filterByFormula(“ IS_BEFORE(TODAY(),{开始日期})”);
$locations->populateRelatedField("Events", $query);
$ locations-> populateRelatedField(“ Events”,$ query);
This will update each record in the $locations collection with associated events that are after TODAY().
Any other linked events will be removed—NOT from the Airtable record, just from the $locations collection.
There are two reasons why AirpressCollections should be used even when dealing with just a single AirpressRecord.
- All Airtable linked fields are arrays, regardless of it you uncheck ‘Allow Linking to Multiple Records’.
- 所有Airtable链接字段都是数组,无论您取消选中“允许链接到多条记录”都是如此。
And until the Airtable Metadata API is available there’s no way to know if your linked record might contain more than one record.
而且,在Airtable Metadata API可用之前,无法知道您的链接记录可能 em>是否包含多个记录。
li>
- Airpress allows you to automatically (or manually) retrieve one or more Airtable records.
- Airpress允许您自动(或手动)检索一个或多个Airtable记录。
And when you're dealing with populating related fields for multiple records, Airpress intelligently aggregates ALL the RECORD_ID()s for the same field in all the records, making a single API request, then “collates” the
而且,当您处理填充多个 em>记录的相关字段时,Airpress会智能地汇总所有记录中同一字段的所有RECORD_ID(),并发出单个API请求,然后“整理”resulting records back into the appropriate “parent” record.
结果记录重新回到适当的“父”记录中。
Essentially, Airpress does everything it can do to minimize the number of API requests.
本质上,Airpress会做 一切 em> strong>,以最大程度地减少API请求的数量。Dealing with just a single record would mean many many more API requests.
仅处理一条记录将意味着更多的API请求。 li>
ol>
Both AirpressCollection() and AirpressRecord() are PHP ArrayObjects.
AirpressCollection()和AirpressRecord()都是PHP ArrayObjects 。
This means that they behave like arrays even though they can store custom properties and methods as well.
这意味着即使它们也可以存储自定义属性和方法,它们的行为也类似于数组。
So for an AirpressRecord $r[“Field Name”] and $r->record_id() both work!
因此,对于AirpressRecord $ r [“字段名称”]和$ r-> record_id()都可以!
This allows easy foreach iteration through records and fields while allowing custom methods as well.
这样可以轻松地遍历记录和字段,同时允许自定义方法。 p>
Airpress needs better documentation regarding how it “implodes” fields from multiple records when using the shortcodes and AirpressCollection methods.
在使用简码和AirpressCollection方法时,Airpress需要更好的文档来说明如何“内嵌”多个记录中的字段。 p>
Airtable Connections
空中连接 h3>
Airtable Connections store your API credentials and allow Airpress to “talk” to the Airtable API.
Airtable Connections存储您的API凭据,并允许Airpress与Airtable API“对话”。
You'll need to enter your API KEY and APP ID.
nofollow“> API密钥和 APP ID 。 p>
Multiple connections to the same base can be used if you want different multiple caching or logging settings.
如果您想要不同的多重缓存或日志记录设置,可以使用到同一基础的多重连接。
For example, you may have a single base but you want all requests made to the Events table to be refreshed every 5 minutes, however any requests made to the Locations table only need to be refreshed daily.
例如,您可能有一个基准,但您希望每5分钟刷新一次对“事件”表的所有请求,但是对“位置”表的任何请求都只需要每天刷新。 p>
The name you give the connection is how you’ll refer to this Connection from other settings pages and in any PHP code you write.
您为连接指定的名称是您如何在其他设置页面以及您编写的任何PHP代码中引用此连接的方式。
(You can also refer to the first connection configuration numerically using a zero-based index).
(您也可以使用从零开始的索引以数字方式引用第一个连接配置) em>。 p> <?php$query = new AirpressQuery();
$ query = new AirpressQuery();
$query->setConfig("default");
$ query-> setConfig(“ default”);
$query->table("My Airtable table name");
$ query-> table(“我的Airtable表名”);
?>
?>
code> pre>
Error Handling
错误处理 h3>
Since version 1.1.46 the AirpressQuery has the hasErrors() and getErrors() methods that should be used when doing any syncing operations as Airtable doesn't have a perfect 'uptime' record and you don't want to sync empty
从1.1.46版本开始,AirpressQuery具有在执行任何同步操作时应使用的hasErrors()和getErrors()方法,因为Airtable没有完美的“正常运行时间”记录,并且您不想同步为空
results just because your request either timed out or return a 422 error or something.
结果仅仅是因为您的请求超时或返回422错误或其他原因。 p>
<?php$query = new AirpressQuery("My Table Name",0);
$ query = new AirpressQuery(“ My Table Name”,0);
$records = new AirpressCollection($query);
$ records = new AirpressCollection($ query);
if ( $query->hasErrors() ){
如果($ query-> hasErrors()){
print_r($query->getErrors());
print_r($ query-> getErrors());
print_r($query->toString());
print_r($ query-> toString());
// or
// 要么
$code = $errors[0]["code"];
$ code = $ errors [0] [“ code”];
$message = $errors[0]["message"];
$ message = $ errors [0] [“ message”];
$string = $query->toString();
$ string = $ query-> toString();
} else if ( is_airpress_empty($records) ) {
} else if(is_airpress_empty($ records)){
// Query was fine, just returned no results
//查询很好,只是没有返回结果
} else {
}其他{
// Do something with $records
//用$ records做点什么
}
}
?>
?>
code> pre>
Caching
缓存 h3>
The Airpress cache saves the results of each Airtable API request using a hash of the request parameters.
Airpress缓存使用请求参数的哈希值保存每个Airtable API请求的结果。
Each subsequent identical request will be served from the local database.
随后的每个相同请求都将从本地数据库提供。 p>
When a cached request is no longer considered “fresh”, the cached result will be served one last time while the cache is updated asynchronously in the background so as not to slow the page load.
当不再将缓存的请求视为“新鲜”时,缓存的结果将在最后一次提供,而缓存在后台异步更新,以免减慢页面加载速度。 p>
If a cached request has expired completely, then the page load will wait for “fresh” data to be requested.
如果缓存的请求已完全过期,则页面加载将等待请求“新鲜”数据。 p>
Airpress gives you control over what is considered “fresh” and “expired” data via these two variables:
Airpress使您可以通过以下两个变量来控制什么是“新鲜”和“过期”数据: p>
Refresh: The number of seconds after which Airpress will perform a background refresh on a cached Airtable API request.
刷新 strong>:Airpress将对缓存的Airtable API请求执行后台刷新的秒数。 p>Expire: The number of seconds after which Airpress will no longer serve the cached request.
有效期 strong>:秒过后,Airpress将不再为缓存的请求提供服务。 p>Query var to force refresh: During development (and even while in production) it can be extremely helpful to force Airpress to load all requests directly from Airpress.
查询变量以强制刷新 strong>:在开发过程中(甚至在生产过程中),强制Airpress直接从Airpress加载所有 em>请求非常有用。Hosts like GoDaddy and MediaTemple already provide a query var to flush the cache, so if you set Airpress’ force refresh to the same var, you can flush everything at once.
像GoDaddy和MediaTemple这样的主机已经提供了一个查询变量来刷新缓存,因此,如果将Airpress的强制刷新设置为相同的变量,则可以立即刷新所有内容。 p>
Assuming “Refresh” is set for five minutes and “Expire” is set for an hour:
假设“刷新”设置为五分钟,“过期”设置为一小时: p>
- Visitor loads a page triggering a request at 8:00am.
- 访问者在8:00 AM加载触发请求的页面。
No cache exists, so data is fetched in real-time, significantly slowing the loading of the page.
不存在缓存,因此将实时获取数据,从而大大减慢了页面的加载速度。 li>
- Visitor reloads the page at 8:04am, so data is fetched from the cache.
- 访问者会在上午8:04重新加载页面,以便从缓存中获取数据。 li>
- Visitor reloads the page at 8:06am (1 minute past the refresh time), so data is loaded from the cache while an asynchronous background request is made to refresh the cache.
- Visitor在上午8:06(刷新时间之后1分钟)重新加载页面,因此,在发出异步后台请求以刷新缓存时,从缓存中加载了数据。
Page load is NOT affected.
页面加载不受影响。 li>
- Visitor reloads the page at 9:07am (1 minute past the exire time—remember the data was last refreshed at 8:06am), so the data is fetched from Airtable in real-time, significantly slowing the loading of the page
- 访问者会在上午9:07(过期时间后1分钟重新加载页面-请记住数据是在上午8:06刷新),因此会从Airtable实时获取数据,从而大大减慢了页面的加载速度
.
。 li>
ol>
Airpress plays nicely with object caches and page caches.
Airpress在对象缓存和页面缓存方面表现出色。
Please note that some hosts aggressively purge the transient cache (which is where cached requests are stored) resulting in more requests than might be expected.
请注意,某些主机会主动清除瞬态缓存(存储缓存的请求的位置),导致请求数量超出预期。
Also, if you have a page cache that bypasses PHP and directly serves cached HTML, then obviously Airpress won’t be able to check the “freshness” of the data until the cached page is regenerated.
另外,如果您有一个绕过PHP并直接提供缓存HTML的页面缓存,那么显然Airpress在重新生成缓存页面之前将无法检查数据的“新鲜度”。 p>
Shortcodes
简码 h3>
- apr_populate
- apr_populate li>
- apr
- apr li>
- apr_include
- apr_include li>
- apr_loop
- apr_loop li>
- apr_loop_0..10
- apr_loop_0..10 li>
ul>
filters
过滤器 h3>
- airpress_configs ($configs array, option group “airpress_cx, airpress_vf, airpress_vp//
- airpress_configs($ configs数组,选项组“ airpress_cx,airpress_vf,airpress_vp // li>
- airpress_include_path_pre ($include)
- airpress_include_path_pre($ include) li>
- airpress_include_path
- airpress_include_path li>
- airpress_shortcode_filter_{date}
- airpress_shortcode_filter_ {date} li>
- airpress_shortcode_filter
- airpress_shortcode_filter li>
- airpress_virtualpost_query
- airpress_virtualpost_query li>
- airpress_virtualpost_last_chance
- airpress_virtualpost_last_chance li>
ul>
Actions
动作 h3>
- airpress_virtualpost_setup
- airpress_virtualpost_setup li>
ul>
Functions
功能 h3>
- airpress_debug
- airpress_debug li>
- is_airpress_force_fresh
- is_airpress_force_fresh li>
- get_airpress_configs
- get_airpress_configs li>
- is_airpress_record
- is_airpress_record li>
- is_airpress_empty
- is_airpress_empty li>
- is_airpress_collection
- is_airpress_collection li>
ul>