Can anyone help me ?
How can I configure the CI database settings programmatically ? I saw this with other systems like OSCommerce, Joomla, WordPress etc..
The user needs to submit a form with database information.
Can anyone help me ?
How can I configure the CI database settings programmatically ? I saw this with other systems like OSCommerce, Joomla, WordPress etc..
The user needs to submit a form with database information.
4
Answers
Since there is no automated CI installer like those for Joomla, WordPress, etc. it is not possible. So, if you need such an opportunity, you’ll have to create such an installer yourself. If you do, don’t forget to share it with the community.
This is actually a pretty complicated process.
MojoMotor which is based on CI has an installation script which makes the additions to
application/config/database.php
which means it’s not impossible.The license agreement for MM prohibits me from posting the actual installation script, but you should be able to create something that works.
Otherwise, imagine something like this:
I haven’t tested this, but I’m trying to implement something like similar to one of my own projects.
I hope this could bring you a little closer.
That approach should be fine. All you need to do is avoid autoloading the DB library in the autoload.php file as it will throw an error everytime you try to load a page otherwise.
You can then have a MY_Controller which has:
You can then extend this to all the controllers that require DB access making sure to exclude the one that the setup runs from.
I found two solutions for this although one I have not yet tested.
There are a lot o projects based on the Codeigniter framework that have some sort of installer. Like “Repox” wrote, you can find this in MojoMotor, there is a core/Config.php extension class that handles this specific task, also Expression Engine has this. Sadly those are under commercial license and cannot be used.
One free application that uses such solution is Ionize CMS.
Take a look at this class: https://github.com/ionize/ionize/blob/master/install/class/Config.php
The second one is in a spark called “files”. You can find it here: http://getsparks.org/packages/files/versions/HEAD/show
The obvious limitation to that is that it rewrites the config file.
This was pointed out somewhat even in “codeigniter github issue 1058” (google that for link) but sadly the developers decided to close it.
Personally I don’t understand why such a feature is not implemented in the framework, it could not only be used to edit the config file at install time but also it could be used in a control panel.