Closed karvaka closed 6 years ago
I had some problems using ActiveRecord virtual attributes with CoordinatesPicker. This pull request enables usage of this feature and allows make things like following:
<?php namespace common\models; /** * Table schema attributes. * @property double $latitude * @property double $longitude * * Overloaded attribute. * @property string|null $coordinates */ class SomePlace extends \yii\db\ActiveRecord { /** * @inheritdoc */ public function rules() { return [ ['coordinates', 'required'], ['coordinates', 'string'] ]; } /** * @return null|string */ public function getCoordinates() { if (!$this->latitude || !$this->longitude) { return null; } return $this->latitude . ',' . $this->longitude; } /** * @param $coordinates */ public function setCoordinates($coordinates) { $parts = explode(',', $coordinates); if (count($parts) === 2) { list($this->latitude, $this->longitude) = $parts; } } }
This approach seems very efficient for me. Much easier to integrate in comparison with this one https://github.com/pigochu/yii2-jquery-locationpicker/blob/master/doc/TWO-FIELDS-CONVERSION.md. Thanks.
Could you pull to branch dev again ? I will test it . Thank you.
I had some problems using ActiveRecord virtual attributes with CoordinatesPicker. This pull request enables usage of this feature and allows make things like following:
This approach seems very efficient for me. Much easier to integrate in comparison with this one https://github.com/pigochu/yii2-jquery-locationpicker/blob/master/doc/TWO-FIELDS-CONVERSION.md. Thanks.