How can i use geoip2 on nette
Notice: This thread is very old.
- Filip Procházka
- Moderator | 4668
If you wanna use this library, you have to define it's classes as services in config.
From the example in readme, I would say you wanna download some
mmdb
file and the load it to the reader. If you have that file
somewhere in your system, you can do it like this.
services:
- GeoIp2\Database\Reader('/usr/local/share/GeoIP/GeoIP2-City.mmdb')
If you have it in your project, let's say in folder data/
, you
can do it like this: Nette will replace the %appDir%
for path to
your app/
directory
services:
- GeoIp2\Database\Reader('%appDir%/../data/GeoIP2-City.mmdb')
Then you can use it in your presenters or other models
class MyPresenter
{
/** @var GeoIp2\Database\Reader @inject */
public $geoip;
public function actionDefault()
{
$record = $this->geoip->city('128.101.101.101');
// ...
}
}
Last edited by Filip Procházka (2014-06-16 18:02)