cethyworks / google-place-autocomplete-bundle
提供一种Google Place Autocomplete类型,这是最简约、最不显眼的实现方式。
v5.1
2019-11-26 16:06 UTC
Requires
- php: ^7.1.3
- cethyworks/content-injector-bundle: ^3.0|^5.0
- symfony/config: ^3.4|~4.2|^5.0
- symfony/dependency-injection: ^3.4|^4.2|^5.0
- symfony/form: ^3.4|^4.2|^5.0
- twig/twig: ^1.0||^2.0|^5.0
Requires (Dev)
- phpunit/phpunit: ^4.8
- symfony/asset: ^3.4|^4.2|^5.0
- symfony/event-dispatcher: ^3.4|^4.2|^5.0
- symfony/framework-bundle: ^3.4|~4.0|^5.0
- symfony/http-foundation: ^3.4|^4.2|^5.0
- symfony/http-kernel: ^3.4|^4.2|^5.0
- symfony/templating: ^3.4|^4.2|^5.0
- symfony/translation: ^3.4|^4.2|^5.0
- symfony/twig-bundle: ^3.4|^4.2|^5.0
- symfony/validator: ^3.4|^4.2|^5.0
README
提供一种Google Place Autocomplete类型,这是最简约、最不显眼的实现方式。
版本
适用于symfony >= 3.4
使用最新版本或 >= v3.3
适用于symfony < 3.4
使用 2.2 或更低版本
安装
1. 使用Composer require命令
$ composer require cethyworks/google-place-autocomplete-bundle
2. 注册bundle
// AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
// ...
new Cethyworks\ContentInjectorBundle\CethyworksContentInjectorBundle(),
new Cethyworks\GooglePlaceAutocompleteBundle\CethyworksGooglePlaceAutocompleteBundle(),
];
// ...
如何使用
1. 可选:添加一个config/packages/cethyworks_google_place_autocomplete.yaml
文件,包含
cethyworks_google_place_autocomplete:
google:
api_key: 'your_api_key'
2. 在你的表单中使用Cethyworks\GooglePlaceAutocompleteBundle\Form\SimpleGooglePlaceAutocompleteType
;
3. 完成!
从Google Place API获取更多数据
如果你需要从地点API结果中获取更多信息,你可以在表单中使用ComplexGooglePlaceAutocompleteType
代替。
与返回简单的string
不同,此类型返回一个Cethyworks\GooglePlaceAutocompleteBundle\Model\Place
对象。
为了持久化它,该bundle提供了doctrine映射,你可以在实体中使用它,如下所示
use Cethyworks\GooglePlaceAutocompleteBundle\Model\Place;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Table(name="dummy_entity")
* @ORM\Entity()
*/
class DummyEntity
{
/**
* @var Place
*
* @ORM\Embedded(class="Cethyworks\GooglePlaceAutocompleteBundle\Model\Place")
*
* @Assert\NotBlank()
*/
private $locationAddress;
// ...
}
工作原理
当使用SimpleGooglePlaceAutocompleteType
或ComplexGooglePlaceAutocompleteType
时,它会自动注册2个InjectorCommands
(一个用于库调用,一个用于输入控件),将必要的javascript代码(包含输入id和google api_key)注入到Response
中。
附加信息
Cethyworks\ContentInjectorBundle
路线图
- 更新README.md,添加将地点转换为其他实体的示例
- 更新地点实体以检索更多数据