rainlab/location-plugin 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

rainlab/location-plugin

Composer 安装命令:

composer require rainlab/location-plugin

包简介

Location plugin for October CMS

README 文档

README

This plugin adds location based features to October CMS.

  • Easily add Country and State to any model
  • Form widget for address lookups (Google API)

View this plugin on the October CMS marketplace:

Extended features

To integrate locations with front-end users, consider also installing the RainLab.UserPlus plugin.

Google API key requirement

Using the Google Maps service requires an API key. You may generate a key from the following link:

Copy the key and enter it in the Settings > Location settings area. If you find the address finder is not working, you may need to enable the Places API and the Maps JavaScript API.

Add Country and State to any model

This plugin provides an easy way to add location fields, country and state, to any model. Simply add these columns to the database table:

$table->bigInteger('country_id')->unsigned()->nullable()->index();
$table->bigInteger('state_id')->unsigned()->nullable()->index();

Then implement the RainLab\Location\Traits\LocationModel trait in the model class:

use \RainLab\Location\Traits\LocationModel;

This will automatically create two "belongs to" relationships:

  1. state - relation for RainLab\Location\Models\State
  2. country - relation for RainLab\Location\Models\Country

Back-end usage

Forms

You are free to add the following form field definitions:

country:
    label: Country
    type: dropdown
    span: left
    placeholder: -- select country --

state:
    label: State
    type: dropdown
    span: right
    dependsOn: country
    placeholder: -- select state --

Lists

For the list column definitions, you can use the following snippet:

country:
    label: Country
    searchable: true
    relation: country
    select: name
    sortable: false

state:
    label: State
    searchable: true
    relation: state
    select: name
    sortable: false

Front-end usage

The front-end can also use the relationships by rendering the @form-select-country and @form-select-state partials provided by the location component. Before proceeding, make sure you have the location component attached to the page or layout.

<div class="form-group">
    <label for="accountCountry">Country</label>
    {% partial '@form-select-country' countryId=user.country_id %}
</div>

<div class="form-group">
    <label for="accountState">State</label>
    {% partial '@form-select-state' countryId=user.country_id stateId=user.state_id %}
</div>

Short Code Accessors

The behavior will also add a special short code accessor and setter to the model that converts country_code and state_code to their respective identifiers.

// Softly looks up and sets the country_id and state_id
// for these Country and State relations.

$model->country_code = "US";
$model->state_code = "FL";
$model->save();

Tailor Content Fields

This plugin provides country and state content field types for use in Tailor blueprints. These fields render as dropdowns populated with countries and states from the location database.

Country Field

fields:
    country:
        label: Country
        type: country
        span: auto
        placeholder: -- select country --

State Field

The state field automatically depends on a country field to filter its options.

fields:
    state:
        label: State
        type: state
        span: auto
        countryFrom: country
        placeholder: -- select state --

The countryFrom option specifies which country field to source the country from (defaults to country). The dependsOn attribute is applied automatically.

Full Example

fields:
    country:
        label: Country
        type: country
        span: auto

    state:
        label: State
        type: state
        span: auto
        countryFrom: country

Address Finder Form Widget

This plugin introduces an address lookup form field called addressfinder. The form widget renders a Google Maps autocomplete address field that automatically populates mapped fields based on the value entered and selected in the address.

Available mappings:

  • street
  • city
  • zip
  • state
  • country
  • country-long
  • latitude
  • longitude
  • vicinity

Available options:

You can restrict the address lookup to certain countries by defining the countryRestriction option. The option accepts a comma separated list of ISO 3166-1 ALPHA-2 compatible country codes (see: https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2).

By default the street mapper places the house number before the street name. However in some countries the number is commonly placed after the street name. You can reverse the order by using the reverseStreetNumber: true option.

Usage:

# ===================================
#  Form Field Definitions
# ===================================

fields:
    address:
        label: Address
        type: addressfinder
        countryRestriction: 'us,ch'
        reverseStreetNumber: false
        fieldMap:
            latitude: latitude
            longitude: longitude
            city: city
            zip: zip
            street: street
            country: country_code
            state: state_code
            vicinity: vicinity

    city:
        label: City
    zip:
        label: Zip
    street:
        label: Street
    country_code:
        label: Country
    state_code:
        label: State
    latitude:
        label: Latitude
    longitude:
        label: Longitude
    vicinity:
        label: Vicinity

License

This plugin is an official extension of the October CMS platform and is free to use if you have a platform license. See EULA license for more details.

rainlab/location-plugin 适用场景与选型建议

rainlab/location-plugin 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 23.31k 次下载、GitHub Stars 达 21, 最近一次更新时间为 2016 年 07 月 16 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「location」 「october」 「octobercms」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 rainlab/location-plugin 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 rainlab/location-plugin 我们能提供哪些服务?
定制开发 / 二次开发

基于 rainlab/location-plugin 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 23.31k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 21
  • 点击次数: 8
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 21
  • Watchers: 8
  • Forks: 47
  • 开发语言: PHP

其他信息

  • 授权协议: proprietary
  • 更新时间: 2016-07-16