私はblog-postなどの簡単な遅延読み込みにelement-apiを使用していましたが、Simple
Mapプラグインが提供するカスタムフィルタを利用して簡単な「Postcode lookup」を作成したいと考えています。
シンプルマップは、アドレスデータと地理位置情報にGoogle Maps APIを使用するカスタムフィールドを提供します。
私の質問はこれです:どのようにカスタムAPIを呼び出すと、私は郵便番号を通過することができるように要素のAPIの
‘基準’設定を使用して(api/customer-search.jsonへのjavascript呼び出しを介して?ポストコード=
M25ND )カスタムフィールドフィルタに基づいて結果を返しますか?
私はCraft 3を使用しています:
"require": {
"php": ">=7.0.0",
"craftcms/cms": "^3.0.0-RC1",
"vlucas/phpdotenv": "^2.4.0",
"roave/security-advisories": "dev-master",
"craftcms/redactor": "1.0.0.1",
"craftcms/element-api": "^2.5",
"ether/simplemap": "^3.1"
},
element-api https://github.com/craftcms/element-api
simple map https://github.com/ethercreative/simplemap
以下は、指定された場所から100マイル以内にあるエントリを返します。
{% set entries = craft.entries.map({
location: 'M2 5ND',
country: 'GB',
radius: 100,
unit: 'mi'
}).orderBy('distance').all() %}
..と私の要素の簡単なルックアップ – api.phpファイルは現在すべての ‘顧客’のエントリを返します:
<?php
namespace Craft;
use craftelementsEntry;
// https://github.com/ethercreative/simplemap
// https://github.com/craftcms/element-api
return [
'defaults' => [
'elementType' => Entry::class,
'elementsPerPage' => 9,
'pageParam' => 'pg',
'resourceKey' => 'entries',
'transformer' => function(Entry $entry) {
return [
'id' => $entry->id,
'title' => $entry->title,
'url' => $entry->url,
'map' => $entry->map,
];
},
],
'endpoints' => [
'api/customer-search.json' => [
'criteria' => [
'section' => 'customers',
'type' => 'customer',
//how to include map({}) filtering of results?
],
],
]
];
What I’m struggling to do is combine the two. As far as I can
tell; element-api criteria only works with the parameters listed
here: https://craftcms.com/docs/templating/craft.entries
あなたが提供できるどんな方向にも事前に感謝します。
modifyElementsQuery
は、 ElementQuery
オブジェクトがビルドされている場所に関係なく起動されなければならないため、同じ方法で動作するはずです。
CraftVariables
entries
関数の EntryQuery rel = “nofollow
noreferrer”> Yiis configure 機能を使用して
'endpoints' => [
'api/customer-search.json' => [
'criteria' => [
'map' => [
'location' => 'M2 5ND',
'country' => 'GB',
'radius' => 100,
'unit' => 'mi'
],
'orderBy' => 'distance'
],
],
]
理論的には同じようなオブジェクトを構築する必要があります
{% set entries = craft.entries.map({
location: 'M2 5ND',
country: 'GB',
radius: 100,
unit: 'mi'
}).orderBy('distance') %}