Modify $settings or $container['my_service'] items permanently with user input from Controller


I am using multiple controller methods for my actions and I need to share variables between them which are supplied by the user at a certain point in time. Later this input is needed for my dependencies in container.

I don’t want to use sessions or globals as this information may be sensitive. What is the best way to permanently change app settings dynamically so these can be then accessed from other controller method later. The below code does not work as it appears that everytime a route/controller method is called, the default settings overwrite whatever I have modified previously.

$settings = $container->get('settings');
        'user_input' => 'my_sensitive_info',

My reduced app code:


$settings = [

$app = new \Slim\App($settings);

require dependencies.php;




// Configuration for Slim Dependency Injection Container
$container = $app->getContainer();

// My service in container to which user_input should be set
$container['my_service'] = function ($c) {
    return new MyService()


Class MyService {

public $user_input;

function setUserInput($user_input){
$this->user_input = $user_input;



//inherits container instance including my_service from BaseController
Class MyControler extends BaseController {

public function login(Request $request, Response $response, $args)

	$user_input = $request->getParsedBody();

//how to pass $user_input to the settings permanently
//or how to modify $container['my_instance'] permanently with setUserInput($user_input)


Thank you for any hints,

I realise my architecture may not be great, but I guess it is often needed to initialize a dependency with dynamic input. I could initialize the dependency in every route, but that seems very annoying.

I don’t understand what are you trying to do…
Anyway you can override it using a container instance.

BTW i suggest you to think your design, because all object should be “ready to be used” after the controller init.

You may use a closures for pass variable from the controller to a container entry, so you may build your service at runtime.
But i don’t really understand what are you trying to do, so any approach i suggest you may be wrong.


Simplified, the question should sound like this : ‘What is the recommended way to make user input availabel for every route in every controller without using sessions/cookies/globals if possible.’

Currently, I am building my service at runtime using user_input already, but I need to build it in every of controller routes, because I did not figure out how to share it between the methods/controllers. Hence my idea was to store this user input in settings or modify the service in container. I can always use session variables, but would prefer not to.

What do you mean for user inputs?
Data sent though HTTP? like get/post data?


The code in controller.php shows how user input is received (and that it comes as a part of login route which may not necessarily be the case but it is here for simplicity).

I don’t understand your problem.

You actually have the user input in the “action” of your controller.
You may use a plain array or a NONHTTPRequest and use them through your layers.