php - How to store and sometimes update a global variable in Silex


I need to do what seems to be a simple thing be can't get it work: I just need a variable (currently an array of dates) to be stored somewhere when a page load, and sometime access and modify thoses dates in other actions of my controller.

I've already tried:

Setting this variable as a member of my customUser class, but I am only able to set it at the creation of the class, I can't update it with new values in other actions, because when i try$app['user']->setDates($dates) and later do$app['user']->getDates(), I get the old, not updated, values.

I also tried to set up a shared service like this:

$app['utils'] = $app->share(function ($app) {
    return new \MyProject\Utils\Utils($app);

which is a simple class with one private member and its associated getter/setter, but still the same issue : when a try to get what I expect to be an updated value, I get the old one.

I'm sure my problem is in my understanding of how Pimple/Silex actually work, could you please explain to me how can I achieve what I am trying to do?

Thank you.

People are also looking for solutions to the problem: php - Access denied for user - (using password: NO)


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.