We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Users' preferences/settings advice requested!

Hi!

I am new to Phalcon and two friends and I are building a little app as a high school project, but we are currently stuck. We need to store a 'user preference' or 'user setting' but we would'nt like it to be in the main databse, so maybe an XML file would do great! Could anyone guide us a bit about that with best practices?

Thank you! :)



17.5k

Why wouldn't you want to store it in a table? It would be pretty simple.

id, user_id, preference_name, preference_value, created, updated, delete are really all the columns you need. User has many preferences. Preference has one user

You could also take it a step further and have a preference types lookup table.

preference_type table would be: id, preference_name, created, updated deleted

preferences table would be: id, user_id, preference_type_id, value, cread, updated, deleted

edited Jan '16

Well, in fact because is ONLY ONE value that ONLY ONE USER (super-admin) can edit.

Btw not a bad advice to future projects!



17.5k

In that case, I would probably store it as an environment variable. https://phalcon.io/setting-up-phalconphp-with-environment-variables

Very cool method but... I don't see in the documentation how code inside Phalcon could change that env. I'll explain a little more: Our app entirely depends on a value that shouldn't be stored in a database, or set as a constant inside the app. It should be variable as the admin-end-user wants. But other kind will only see it as a non-editable field. I mean, a specific role of end user needs to change it.



879
Accepted
answer

For static value, I put them in config.php https://docs.phalcon.io/en/latest/reference/config.html.

For flexible config, I'm using json inside the database.

A JSON file is a good idea! Done with it. Thank you!



17.5k

JSON file in the UI? If so, that is easily hacked...

Hmmm... I didn't think so. If you have a better suggestion please help us :)

JSON file in the UI? If so, that is easily hacked...



17.5k

My suggestion was/is to keep the setting on the server. Otherwise, people can intercept/fake it through the UI and see things they shouldn't see.