How to insert new parameters to config.neon?

Notice: This thread is very old.
medhi
Generous Backer | 255
+
0
-

I have users saved in config.neon (https://doc.nette.org/…thentication) and I want to add new users thru a form (web interface). How it is possible?

Šaman
Member | 2659
+
0
-

I think it's no posiible. Config.neon is for configuration, not data store. You need database.

bazo
Member | 620
+
0
-

it is possible.

you need to read the .neon file contents using NeonAdapter, then merge the resulting array with your new data and write it back using NeonAdapter again.

or just use file_get_contents and Neon:decode and vice-versa

David Grudl
Nette Core | 8218
+
0
-

Oh, why use the hardcore solution?

config:

parameters:
	users:
		john: password

services:
	- MyAuthenticator(..., %users%)

and authenticator:

class MyAuthenticator extends Nette\Object implements Nette\Security\IAuthenticator
{

	public function __construct(Nette\Database\Context $database, array $users)
	{
		$this->database = $database;
		$this->users = $users;
	}
medhi
Generous Backer | 255
+
0
-

David Grudl: But how to write a new user into the config? I can't see it in your example. If I am missing something, please be more explanatory.

Filip Procházka
Moderator | 4668
+
0
-

Create file app/config/users.neon that you can write and read using Neon and include it

bazo
Member | 620
+
0
-

how is this different from my solution?

medhi
Generous Backer | 255
+
0
-

bazo, Filip: OK, you say work with extra neon file, which is included into main config file. Seems fine.

Filip Procházka
Moderator | 4668
+
0
-

When you have extra config, you simply load only users data, do whatever and write them. You don't rewrite database connections, services, … Which I'm not saing it wouldn't work, it's just not neccesary. Separating the configs feels cleaner.

mrataja
Member | 57
+
0
-

When I include files in config.neon
includes:
parameters.php

How can I reach variables in parameters.php file?

Filip Procházka
Moderator | 4668
+
0
-

You just return the structure

<?php

return array( // parameters.php
	'parameters' => array(...),
	'nette' => array(...),
);

Last edited by Filip Procházka (2014-01-23 16:19)