I am trying to use the Configure
class in CakePHP, but I'm not sure if I am using it correctly. I have read through the cook book and the API, but I can't seem to do what I want.
I have created a configuration file: app/config/config.ph开发者_开发问答p. I can directly edit this file and set variables in there and access them using Configure::read()
.
Is it possible to update the values of the configuration file from the application itself, i.e., from a controller? I have tried using Configure::write()
, but this does not seem to change the value.
app/config/config.php
isn't a file that's automatically loaded by Cake. Either move these variables into app/config/bootstrap.php
or tell your bootstrap.php
file to load your custom file. You could also put your variables in app/config/core.php
, but I'd recommend against that. I tend to like leaving that file alone and adding/overwriting values in bootstrap.php
.
According to the API, Configure is supposed to be used "for managing runtime configuration information".
You can use its methods to create, read, update and delete (CRUD) configuration variables at runtime. The Configure class is available everywhere in your CakePHP application and therefore CRUD operations performed on its data in any place, including a controller.
If you are looking for persistent storage, you could consider a database (SQL or NoSQL). I would not recommend using a text file, as it raises a lot of security concerns. Even if security is not an issue, a database is propably a more fitting solution.
More on the Configure class in the Cookbook.
精彩评论