Welcome Guest, Not a member yet? Register   Sign In
How reload config file
#11

(This post was last modified: 02-25-2020, 12:17 AM by omid_student.)

(02-19-2020, 08:00 AM)InsiteFX Wrote: You could make your own config file and always load that one when needed.
using the config load method.
I use it but dont happen when i try reload int

(02-22-2020, 10:15 PM)murugappan Wrote: I am a bit confused. I had the same trouble but when i came to think about it, i realized what i was doing is a mistake. Let me explain. The values in the config file are like constants relating to the settings. If my understanding is correct, these settings should be fixed and should put into our own config.php file. The file can be autoloaded each time. If changes are allowed to be made, then these should be loaded into a database table or json/ini files.
Look when i reload file in long process,i will see real data in file
But when i include "config.php" again
The new values does not replaced with old value
Reply
#12

(02-19-2020, 08:00 AM)InsiteFX Wrote: You could make your own config file and always load that one when needed.
using the config load method.
Please see my code :
PHP Code:
include APPPATH.'config/my_config.php';
            echo 
config_item('from_email'); 

When i receive new signal from user,i try to load again file and send new data
but not loading correctly and i dont have new data
Why?

(I use socket in this project and when i receive new packet,i check it and return valid data)
Reply
#13

You can try my registry class and helper to see if it will do what you need.

Class Registry:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * ------------------------------------------------------------------------
 * Editor   : PhpStorm 2019.3
 * Date     : 6/23/2019
 * Time     : 6:03 AM
 * Authors  : Raymond L King Sr.
 * ------------------------------------------------------------------------
 * 
 * Class        Name
 * 
 * @project     fxstarter
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2019 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ------------------------------------------------------------------------
 */

/**
 * SETUP:
 *
 * place this library in ./application/libraries/Registry.php
 *
 * Autoload: ./application/libraries/Registry.php
 * Autoload: ./application/helpers/registry_helper.php
 *
 * TESTING:
 *
 * In your Controller index method add.
 *
 *         regSet('1', 'test1', 'test1');
 *         regSet('1', 'test2', 'test1');
 *         regSet('1', 'test3', 'test1');
 *
 *         regSet('2', 'test4', 'test2');
 *         regSet('2', 'test5', 'test2');
 *         regSet('2', 'test6', 'test2');
 *
 *         $result  = regGet('1', 'test3');
 *         $result1 = regGet_index('2');
 *         $exist   = regExists('2', 'test1');
 *
 *         $result2 = regDelete('1', 'test3');
 *
 *         // Remove the remarks // to reset and clear out the reg array.
 *         // regClear();
 *
 * DEBUG:
 *
 *         var_dump($this->registry->debugRegistry());
 *
 *         $this->registry->var_debug($this->registry->debugRegistry(), $result, $result1, $exist, $result2);
 *
 * USAGE:
 *
 * set:            $this->registry->set('1', 'test1', 'test1');
 * get:            $result = $this->registry->get('1', 'test3');
 * getIndex     $result = $this->registry->getIndex('2');
 * exists:        $result = $this->registry->exists('2', 'test1');
 * clear:        $this->registry->clear();
 * delete:        $result2 = $this->registry->delete('1', 'test3');
 *
 */

class Registry {

    
/**
     * Class variables - public, private, protected and static.
     * --------------------------------------------------------------------
     */

    /**
     * @var
     * CI Super Object.
     */
    
private $_ci;

    
/**
     * @var
     * array ( $key => $val );
     */
    
protected static $reg = array();

    
/**
     * __construct ()
     * --------------------------------------------------------------------
     *
     * Constructor    PHP 5+
     *
     * NOTE: Not needed if not setting values or extending a Class.
     *
     */
    
public function __construct()
    {
        
$this->_ci =& get_instance();

        
log_message('debug'"Registry Class Initialized");
    }

    
/**
     * set ()
     * --------------------------------------------------------------------
     *
     * Set a registry key and value pair.
     *
     * @param   $key
     * @param   $val
     */
    
public function set($key$val)
    {
        if ( ! isset(
self::$reg[$key]))
        {
            
self::$reg[$key] = $val;
        }
    }

    
/**
     * get ()
     * --------------------------------------------------------------------
     *
     * Gets a registry and value.
     *
     * @param   $key
     * @return  bool
     */
    
public function get($key)
    {
        if (isset(
self::$reg[$key]))
        {
            return 
self::$reg[$key];
        }

        return 
false;
    }

    
/**
     * exists ()
     * --------------------------------------------------------------------
     *
     * Checks to see if a registry exists.
     *
     * @param   $key
     * @return  bool
     */
    
public function exists($key)
    {
        return isset(
self::$reg[$key]);
    }

    
/**
     * clear ()
     * --------------------------------------------------------------------
     *
     * Clears out and resets the registry arrays.
     */
    
public function clear()
    {
        
self::$reg = array();
    }

    
/**
     * delete ()
     * --------------------------------------------------------------------
     *
     * Deletes a registry key.
     *
     * @param   $key
     * @return  bool
     */
    
public function delete($key)
    {
        if (isset(
self::$reg[$key]))
        {
            unset(
self::$reg[$key]);

            return 
true;
        }

        return 
false;
    }

    
/**
     * debugRegistry ()
     * --------------------------------------------------------------------
     *
     * Debug the reg arrays.
     *
     * @return  array
     */
    
public function debugRegistry()
    {
        return 
self::$reg;
    }

}
   // End of Registry Class.

/**
 * ------------------------------------------------------------------------
 * Filename: Registry.php
 * Location: ./application/libraries/Registry.php
 * ------------------------------------------------------------------------
 */ 

Helper registry_helper:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * ------------------------------------------------------------------------
 * Editor   : PhpStorm 2019.3
 * Date     : 6/23/2019
 * Time     : 6:27 AM
 * Authors  : Raymond L King Sr.
 * ------------------------------------------------------------------------
 * 
 * Class        registry_helper
 * 
 * @project     fxstarter
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2019 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ------------------------------------------------------------------------
 */

/**
 * -----------------------------------------------------------------------
 * Place in application/helpers/registry_helper.php
 * -----------------------------------------------------------------------
 */

/**
 * ci ()
 * -----------------------------------------------------------------------
 *
 * The CodeIgniter Super Object
 */
if ( ! function_exists('ci'))
{
    
/**
     * ci ()
     * -------------------------------------------------------------------
     *
     * @return CI_Controller
     */
    
function ci()
    {
        return 
get_instance();
    }
}

/**
 * regSet ()
 *
 * Sets a new property.
 *
 * Usage: regSet($key, $val);
 */
if ( ! function_exists('regSet'))
{
    
/**
     * regSet ()
     * --------------------------------------------------------------------
     *
     * @param   string $key
     * @param   string $val
     */
    
function regSet($key ''$val '')
    {
        
ci()->registry->set($key$val);
    }
}

/**
 * regGet ()
 *
 * Gets a registry value.
 *
 * Usage: $result = regGet($key);
 */
if ( ! function_exists('regGet'))
{
    
/**
     * regGet ()
     * --------------------------------------------------------------------
     *
     * @param   string $key
     * @return  mixed
     */
    
function regGet($key '')
    {
        return 
ci()->registry->get($key);
    }
}

/**
 * regExists ()
 *
 * Checks to see if a registry key exists.
 *
 * Usage: $result = regExists($key);
 */
if ( ! function_exists('regExists'))
{
    
/**
     * regExists ()
     * --------------------------------------------------------------------
     *
     * @param   string $key
     * @return  mixed
     */
    
function regExists($key '')
    {
        return 
ci()->registry->exists($key);
    }
}

/**
 * regDelete ()
 *
 * Deletes a registry index and key.
 *
 * Usage: $result = regDelete($index, $key);
 */
if ( ! function_exists('regDelete'))
{
    
/**
     * regDelete ()
     * --------------------------------------------------------------------
     *
     * @param   string $key
     * @return  mixed
     */
    
function regDelete($key '')
    {
        return 
ci()->registry->delete($key);
    }
}

/**
 * regClear ()
 *
 * Resets and clears out the registry arrays.
 *
 * Usage: regClear();
 */
if ( ! function_exists('regClear'))
{
    
/**
     * reg_clear ()
     * --------------------------------------------------------------------
     *
     */
    
function regClear()
    {
        
ci()->registry->clear();
    }
}

/**
 * ------------------------------------------------------------------------
 * Filename: registry_helper.php
 * Location: ./application/helpers/registry_helper.php
 * ------------------------------------------------------------------------
 */ 

You could now write your own methods to save the reg array to a database table etc;
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#14

(02-25-2020, 09:12 AM)InsiteFX Wrote: You can try my registry class and helper to see if it will do what you need.

Class Registry:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * ------------------------------------------------------------------------
 * Editor   : PhpStorm 2019.3
 * Date     : 6/23/2019
 * Time     : 6:03 AM
 * Authors  : Raymond L King Sr.
 * ------------------------------------------------------------------------
 * 
 * Class        Name
 * 
 * @project     fxstarter
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2019 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ------------------------------------------------------------------------
 */

/**
 * SETUP:
 *
 * place this library in ./application/libraries/Registry.php
 *
 * Autoload: ./application/libraries/Registry.php
 * Autoload: ./application/helpers/registry_helper.php
 *
 * TESTING:
 *
 * In your Controller index method add.
 *
 * regSet('1', 'test1', 'test1');
 * regSet('1', 'test2', 'test1');
 * regSet('1', 'test3', 'test1');
 *
 * regSet('2', 'test4', 'test2');
 * regSet('2', 'test5', 'test2');
 * regSet('2', 'test6', 'test2');
 *
 * $result  = regGet('1', 'test3');
 * $result1 = regGet_index('2');
 * $exist   = regExists('2', 'test1');
 *
 * $result2 = regDelete('1', 'test3');
 *
 * // Remove the remarks // to reset and clear out the reg array.
 * // regClear();
 *
 * DEBUG:
 *
 * var_dump($this->registry->debugRegistry());
 *
 * $this->registry->var_debug($this->registry->debugRegistry(), $result, $result1, $exist, $result2);
 *
 * USAGE:
 *
 * set: $this->registry->set('1', 'test1', 'test1');
 * get: $result = $this->registry->get('1', 'test3');
 * getIndex     $result = $this->registry->getIndex('2');
 * exists: $result = $this->registry->exists('2', 'test1');
 * clear: $this->registry->clear();
 * delete: $result2 = $this->registry->delete('1', 'test3');
 *
 */

class Registry {

 
/**
 * Class variables - public, private, protected and static.
 * --------------------------------------------------------------------
 */

 /**
 * @var
 * CI Super Object.
 */
 
private $_ci;

 
/**
 * @var
 * array ( $key => $val );
 */
 
protected static $reg = array();

 
/**
 * __construct ()
 * --------------------------------------------------------------------
 *
 * Constructor    PHP 5+
 *
 * NOTE: Not needed if not setting values or extending a Class.
 *
 */
 
public function __construct()
 {
 
$this->_ci =& get_instance();

 
log_message('debug'"Registry Class Initialized");
 }

 
/**
 * set ()
 * --------------------------------------------------------------------
 *
 * Set a registry key and value pair.
 *
 * @param   $key
 * @param   $val
 */
 
public function set($key$val)
 {
 if ( ! isset(
self::$reg[$key]))
 {
 
self::$reg[$key] = $val;
 }
 }

 
/**
 * get ()
 * --------------------------------------------------------------------
 *
 * Gets a registry and value.
 *
 * @param   $key
 * @return  bool
 */
 
public function get($key)
 {
 if (isset(
self::$reg[$key]))
 {
 return 
self::$reg[$key];
 }

 return 
false;
 }

 
/**
 * exists ()
 * --------------------------------------------------------------------
 *
 * Checks to see if a registry exists.
 *
 * @param   $key
 * @return  bool
 */
 
public function exists($key)
 {
 return isset(
self::$reg[$key]);
 }

 
/**
 * clear ()
 * --------------------------------------------------------------------
 *
 * Clears out and resets the registry arrays.
 */
 
public function clear()
 {
 
self::$reg = array();
 }

 
/**
 * delete ()
 * --------------------------------------------------------------------
 *
 * Deletes a registry key.
 *
 * @param   $key
 * @return  bool
 */
 
public function delete($key)
 {
 if (isset(
self::$reg[$key]))
 {
 unset(
self::$reg[$key]);

 return 
true;
 }

 return 
false;
 }

 
/**
 * debugRegistry ()
 * --------------------------------------------------------------------
 *
 * Debug the reg arrays.
 *
 * @return  array
 */
 
public function debugRegistry()
 {
 return 
self::$reg;
 }

}
   // End of Registry Class.

/**
 * ------------------------------------------------------------------------
 * Filename: Registry.php
 * Location: ./application/libraries/Registry.php
 * ------------------------------------------------------------------------
 */ 

Helper registry_helper:

PHP Code:
<?php
defined
('BASEPATH') OR exit('No direct script access allowed');

/**
 * ------------------------------------------------------------------------
 * Editor   : PhpStorm 2019.3
 * Date     : 6/23/2019
 * Time     : 6:27 AM
 * Authors  : Raymond L King Sr.
 * ------------------------------------------------------------------------
 * 
 * Class        registry_helper
 * 
 * @project     fxstarter
 * @author      Raymond L King Sr.
 * @link        http://www.procoversfx.com
 * @copyright   Copyright (c) 2009 - 2019 Pro Covers FX, LLC.
 * @license     http://www.procoversfx.com/license
 * ------------------------------------------------------------------------
 */

/**
 * -----------------------------------------------------------------------
 * Place in application/helpers/registry_helper.php
 * -----------------------------------------------------------------------
 */

/**
 * ci ()
 * -----------------------------------------------------------------------
 *
 * The CodeIgniter Super Object
 */
if ( ! function_exists('ci'))
{
 
/**
 * ci ()
 * -------------------------------------------------------------------
 *
 * @return CI_Controller
 */
 
function ci()
 {
 return 
get_instance();
 }
}

/**
 * regSet ()
 *
 * Sets a new property.
 *
 * Usage: regSet($key, $val);
 */
if ( ! function_exists('regSet'))
{
 
/**
 * regSet ()
 * --------------------------------------------------------------------
 *
 * @param   string $key
 * @param   string $val
 */
 
function regSet($key ''$val '')
 {
 
ci()->registry->set($key$val);
 }
}

/**
 * regGet ()
 *
 * Gets a registry value.
 *
 * Usage: $result = regGet($key);
 */
if ( ! function_exists('regGet'))
{
 
/**
 * regGet ()
 * --------------------------------------------------------------------
 *
 * @param   string $key
 * @return  mixed
 */
 
function regGet($key '')
 {
 return 
ci()->registry->get($key);
 }
}

/**
 * regExists ()
 *
 * Checks to see if a registry key exists.
 *
 * Usage: $result = regExists($key);
 */
if ( ! function_exists('regExists'))
{
 
/**
 * regExists ()
 * --------------------------------------------------------------------
 *
 * @param   string $key
 * @return  mixed
 */
 
function regExists($key '')
 {
 return 
ci()->registry->exists($key);
 }
}

/**
 * regDelete ()
 *
 * Deletes a registry index and key.
 *
 * Usage: $result = regDelete($index, $key);
 */
if ( ! function_exists('regDelete'))
{
 
/**
 * regDelete ()
 * --------------------------------------------------------------------
 *
 * @param   string $key
 * @return  mixed
 */
 
function regDelete($key '')
 {
 return 
ci()->registry->delete($key);
 }
}

/**
 * regClear ()
 *
 * Resets and clears out the registry arrays.
 *
 * Usage: regClear();
 */
if ( ! function_exists('regClear'))
{
 
/**
 * reg_clear ()
 * --------------------------------------------------------------------
 *
 */
 
function regClear()
 {
 
ci()->registry->clear();
 }
}

/**
 * ------------------------------------------------------------------------
 * Filename: registry_helper.php
 * Location: ./application/helpers/registry_helper.php
 * ------------------------------------------------------------------------
 */ 

You could now write your own methods to save the reg array to a database table etc;

It is very good Thanks
Can i use this library for config file for codeigniter?
Reply
#15

Yes, but you would need to modify it to use the CI style of parameters.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply
#16

(02-25-2020, 12:49 PM)InsiteFX Wrote: Yes, but you would need to modify it to use the CI style of parameters.
Thank you
Reply




Theme © iAndrew 2016 - Forum software by © MyBB