Welcome Guest, Not a member yet? Register   Sign In
With passing parameters when initializing my library using an "Auto-load"
#1

[eluser]Spectruman[/eluser]
With passing parameters when initializing my library using an "Auto-load" feature without go class my controller

example
Code:
$_arrayParams = array('typeMenu' => 'vertical', 'orderItensMenuMain' => 'edit_inf_order',
                        'orderItensSubMenu' => 'edit_inf_order');
        
$this->load->library('menu_superfish',$_arrayParams);

I tried this way without success
Code:
$_arrayParams = array('typeMenu' => 'vertical', 'orderItensMenuMain' => 'edit_inf_order',
                        'orderItensSubMenu' => 'edit_inf_order');

$autoload['libraries'] = array('database',array('menu_superfish',$_arrayParams));

this question how to do this with appeal autoloading codeigniter [code]$autoload['libraries'] = ???
#2

[eluser]WanWizard[/eluser]
The CI standard way of configuring a library is through a config file in application/config. It needs to have the same name as the library.
See the user guide for more information.
#3

[eluser]Spectruman[/eluser]
[quote author="WanWizard" date="1282336316"]The CI standard way of configuring a library is through a config file in application/config. It needs to have the same name as the library.
See the user guide for more information.[/quote]

I confess I did not understand, I looked in the guide as well. You could show an example?
#4

[eluser]WanWizard[/eluser]
Create a file called menu_superfish.php in application/config, and in that, create a structure like
Code:
<?php    if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
* menu_superfish Configuration
*/

$config['keyA']                     = 'valueA';
$config['keyB']                     = 'ValueB';

Then create your library like
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Menu_superfish {

    function Menu_superfish($params)
    {
        // process the parameters passed
    if (is_array($params) && count($params) > 0)
    {
        foreach ($params as $key => $val)
        {
            // only load keys we have defined as class properties
            // you might want to add more checks here
            if ( isset( $this->$key )
            {
                $this->$key = $val;
            }
        }
    }
    }
}

?>

This allows you to load the library from autoload, or via $this->load->library(), and all config will be loaded from the config file.

Alternatively, you can do $this->load->library('menu_superfish', $config); where $config is an array similar to the one you define in the config file. This allows you to override a config file.




Theme © iAndrew 2016 - Forum software by © MyBB