How to insert new parameters to config.neon?

6 years ago

medhi
Bronze Partner | 189
+
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?

6 years ago

Šaman
Member | 2341
+
0
-

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

6 years ago

bazo
Member | 625
+
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

6 years ago

David Grudl
Nette Core | 6877
+
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;
    }

6 years ago

medhi
Bronze Partner | 189
+
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.

6 years ago

Filip Procházka
Moderator | 4693
+
0
-

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

6 years ago

bazo
Member | 625
+
0
-

how is this different from my solution?

6 years ago

medhi
Bronze Partner | 189
+
0
-

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

6 years ago

Filip Procházka
Moderator | 4693
+
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.

6 years ago

mrataja
Member | 58
+
0
-

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

How can I reach variables in parameters.php file?

6 years ago

Filip Procházka
Moderator | 4693
+
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)