Welcome Guest, Not a member yet? Register   Sign In
few general questions about configuration in release
#1

[eluser]chejnik[/eluser]
Hello,
I would like to release an Dictionary application, that can anyone install to your server and use it there.
Is there a simple way to override database confiration settings in config/database.php or is it better to use some new created config file with database configuration settings and other stuff?

This function I have found creates simple config array
Code:
// $toconfig is simple array like this
$toconfig = array (
            'hostname' => $_POST["hostname"],
            'database' => $_POST["database"],
            'username' => $_POST["username"],
            'password' => $_POST["password"],
            'dbdriver' => $_POST["dbdriver"],
            'dbprefix' => $_POST["dbprefix"],
            );
function make_config($toconfig)
    {
        $this->config->load('myconfig', TRUE);
        $myconfig = $this->config->item('myconfig');
        $result = array_merge($myconfig, $toconfig);
        $data = '<?php' . "\n" . 'if (!defined("BASEPATH")) exit("No direct script access allowed");' . "\n" . '$config = ' . var_export($result, true) . "\n" . '?>';
        write_file(APPPATH . 'config/myconfig.php', $data);
        }
I wonder how would you solve it. Thank you
#2

[eluser]Chris Newton[/eluser]
If you want to make it easy, write an installer script that gather's the users information and writes the config/database.php file. Codeextinguisher has an installer that does something like this.
#3

[eluser]chejnik[/eluser]
Hello,
I will post my sollution for other users.

In step 4 of installation I gathered database information and in step 5 I wrote them to config file

Code:
function install5()
    {
       $myDatabaseSettings = array ( 'myDatabaseSettings' => array (
            'hostname' => $_POST["hostname"],
            'database' => $_POST["database"],
            'username' => $_POST["username"],
            'password' => $_POST["password"],
            'dbdriver' => $_POST["dbdriver"],
            'dbprefix' => $_POST["dbprefix"],
            'pconnect' => TRUE,
            'db_debug' => TRUE,
            'cache_on' => FALSE,
            'cachedir' => "",
            'char_set' => "utf8",
            'dbcollat' => "utf8_general_ci"            
            ),
            );
    
        $this->makeConfigNew($myDatabaseSettings); // call to function bellow
        $this->load->view('install/installview5', $data);
    
    }

And function that writes the database config array into file (this time called mydatabase.php)

Code:
function makeConfigNew($toconfig)
    {
        
        $myDatabaseSettings2 = array ( 'default' =>
                array (
            'hostname' => "localhost",
            'database' => "",
            'username' => "root",
            'password' => "",
            'dbdriver' => "mysql",
            'dbprefix' => "",
            'pconnect' => TRUE,
            'db_debug' => TRUE,
            'cache_on' => FALSE,
            'cachedir' => "",
            'char_set' => "utf8",
            'dbcollat' => "utf8_general_ci"            
            ),
            );        
            
        $result = array_merge($myDatabaseSettings2, $toconfig);
                
                $data = '<?php' . "\n" . 'if (!defined("BASEPATH")) exit("No direct script access allowed");' . "\n";
        $data .= '$active_group = "myDatabaseSettings";';
        $data .= "\n";
        $data .= '$active_record = TRUE;';
        $data .= "\n";
        $data .= "\n";
        $data .= '$db = ' . var_export($result, true) . "\n" . '?>';

        write_file(APPPATH . '/config/mydatabase.php', $data, 'w+');
        log_message('info', "we make a config file");        
    }

Hopefully it will help someone. Bye bye Ales




Theme © iAndrew 2016 - Forum software by © MyBB