Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I am looking for the best way to store the application editable settings (ex: Site Name, Is the site closed? .. etc).
It seems like Database is not the best way because I don't want to use a database just for 2 or 3 settings!
So I went to PHP Array but how can I edit it?!
I have reviewed all questions related to this, but I can not find a useful answer for me.
Note: I don't want to edit the settings manually. I want to edit it by php.
You can store the settings in a config file in form of serialized array or JSON.
Say, reading settings:
$settings = json_decode( file_get_contents('settings.cfg') );
Saving settings back:
file_put_contents('settings.cfg', json_encode($settings) );
Of course the file should be writeable permission wise.
You can store anything you want in this array, even simple objects and complex arrays. And as it is JSON you can edit the file manually, too. If a need arises.
Related
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 11 days ago.
Improve this question
My goal is to add pictures inserted by user into a database. So I'm trying to set their names to the date of their creation. The format is "day.month.year hour.minute.second". But I'm facing the problem that the only one picture is added to the catalog. I'm thinking that the reason why it happens is because the script runs too fast for a second to pass.
And that made me think if this is a good idea to name pictures this way.
I started to assume that maybe I need to use some kind of library to manually add a second to every next picture's name.
But before doing that I decided to go ask somebody more profecient than me in order to undesrtand whether I need to do it this way or maybe there's a better one
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
So I'm having some trouble explaining to my buddy why a specific piece of code is "bad practice", does anyone know where I can find some information on why it's a bad way to do it? (Or maybe it's just me who think it's bad).
Here's what he wants to accomplish:
Create a "dynamic form input", so he will create a table with different types of cols. And then in the file that shows the form he will just make alot of different "if type == varchar" etc. and then display a form after that
When saving a form he will loop thru all the $_POST data and insert it into a table depending on the key's etc.
He want's to make everything dynamic and I can see why that could be cool, but in my book this seems to be very bad practice, so is there a better way to do this or is there some articles I can show him about why this is bad etc.?
Everything is for a private admin panel, but still I feel there is a lot of issues.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
I'm currently working on a project that uses MySQL for configuration, but now I'm starting to think it could slow down page loads.
So my question is, would it be better to store configuration options (that are read almost every page load) inside an XML/JSON file, or a MySQL database?
Thanks.
One thing to conside is how much config data there is, and perhaps how often it is likely to change. If the amount of data is small, then saving this in a database (if your not already using a db for anything else), would be overkill, equally maintaining a db for something that gets changed once every 6 months would probably be a waste of resources.
I think this depends on your projects. If you want someone else to configure the application through the UI you can put the configurations into the database.
If its just you and some developers, and changes are not made frequently, put them in a file.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
All,
I'm curious what the best approach to this would be. In case the tags weren't noticed, I'm using PHP and Laravel 4.
My application requires that users register with an email address that is from specific domain names. Currently there is only one domain, however, I can see it being a requirement to white list others.
I would assume it would be best to put the domains into an array. Would I run a regex from $rules array against that array? I'm somewhat green to regex. I don't use it often enough to commit anything advanced to memory so feel free to talk to me like a 2 year old.
You can create a custom validator for this. See http://laravel.com/docs/validation#custom-validation-rules for reference.
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have been working on creating a script that can let a program setup itself the way Magento does.
I mean I want to let the user enter his hostname, username, password, database name in the input boxes and then store it somewhere with my files.
I'm exactly getting no idea on I should directly write a code that will create a connect.php file for itself or I should store the values in text or any soe file with some xyz format and then access it each time to make connection to database.
In either case, pls help me out.
You need to do some Store Configuration via your modules system.xml file.
Then you can save the config via Magento Administration and read the configuration in your custom code via Mage:getStoreConfig().
Alan Storm has an excellent tutorial on this, so no need to explain a second time:
http://alanstorm.com/custom_magento_system_configuration