Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

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! :)



10.6k

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!



10.6k

In that case, I would probably store it as an environment variable. http://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.phalconphp.com/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!



10.6k

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...



10.6k

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.