Problem with Nette\Databases\Context – nette 2.3

Notice: This thread is very old.
lukin
Member | 12
+
-1
-

I use Nette\Databases\Conection for conection o DB and than apply Context. If I use Context I get an exception.

Argument 2 passed to Nette\Database\Context::__construct() must be an instance of Nette\Database\IStructure, null given, called in

On version nette 2.2.7 is OK, in version 2.3 not working.

<?php
use Nette\Database\Connection,
	Nette\Database\Context;
...
$conn_agenda = new Connection('mysql:host='.$DB_AGENDA->HOST.';dbname='.$DB_AGENDA->DB, $DB_AGENDA->USER, $DB_AGENDA->PASSWD);
$db_agenda = new Context($conn_agenda);
?>
greeny
Member | 405
+
0
-

First of all, you should get your services (e.g. Database) by DI.

The error you are getting is pretty much user-friendly. You should read it. Missing second argument for Nette\Database\Context, you have to pass instance of Nette\Database\IStructure there. Which needs connection and cache. Which needs cache storage. This is way to hell, use DI.

Michal Vyšinský
Member | 608
+
+3
-

You need to create instance of Nette\Database\Structure which constructor accepts Connection and CacheStorage.

You can do it like a here:https://github.com/…grations.php#L20

lukin
Member | 12
+
0
-

greeny wrote:

First of all, you should get your services (e.g. Database) by DI.

The error you are getting is pretty much user-friendly. You should read it. Missing second argument for Nette\Database\Context, you have to pass instance of Nette\Database\IStructure there. Which needs connection and cache. Which needs cache storage. This is way to hell, use DI.

Yes, I know.
But it is very old project. The project not use DI.

Problem is, if anyone try out the example of documentation.
https://doc.nette.org/cs/database

Example from url not working in nette 2.3.

lukin
Member | 12
+
0
-

Michal Vyšinský wrote:

You need to create instance of Nette\Database\Structure which constructor accepts Connection and CacheStorage.

You can do it like a here:https://github.com/…grations.php#L20

Thanks, is working.