How can i use geoip2 on nette

Notice: This thread is very old.
alnux
Member | 139
+
0
-

Hi i just want to add geoip2 extension and i think that on nette it will be like service could you help me how to conf on config.neon to work with it.

by the way i downloaded like composer package

requiere "geoip2/geoip2": "0.6.*"
Filip Procházka
Moderator | 4668
+
0
-

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)

alnux
Member | 139
+
0
-

I supposed something like that , thanks for clarifying me the issue