Page 1 of 1

$this->config->get not working for me

Posted: Wed Dec 26, 2012 5:28 am
by haosmark
I'm trying to save and retrieve settings, but it isn't working out. I keep getting this error:
Notice: Undefined property: Config::$get in C:\UwAmp\www\opencart\admin\controller\design\banner.php on line 66
This is what my code is like:

Code: Select all

    private function saveNivoSettings() {
        $this->load->model('setting/setting');
        $posted_data = $this->request->post;

        //extract titles
        for($i=0; $i < sizeof($posted_data['banner_image']); $i++) {
            $titles[] = $posted_data['banner_image'][$i]['banner_image_description'][1]['title'];
        }
        //extract speed
        for($i=0; $i < sizeof($posted_data['effect_speed']); $i++)
            $nivo_settings[$titles[$i] . '-speed'] = $posted_data['effect_speed'][$i];

        //extract labels
        for($i=0; $i < sizeof($posted_data['effect_label']); $i++)
            $nivo_settings[$titles[$i] . '-label'] = $posted_data['effect_label'][$i];

        $this->model_setting_setting->editSetting('nivoslider', $nivo_settings);

        die($this->config->get['next-banner-speed']);
    }
This creates an associative array with titles (galaxy-tab-speed, other-stuff-speed, other-stuff-label) and values for those titles. Then I save it to nivoslider settings, but when I try to retrieve the setting by its title I get an error.
What am I doing wrong here?

Re: $this->config->get not working for me

Posted: Wed Dec 26, 2012 9:59 am
by Johnathan
$this->config->get() is a function, not an array, so it needs regular parentheses and not square brackets. So your code would need to be:

Code: Select all

$this->config->get('next-banner-speed')
If you want to comply with standard OpenCart conventions, you should also note that settings use underscores, not hyphens, and are prefixed with the group of settings that it involves. (For example, slideshow_next_banner_speed)

Re: $this->config->get not working for me

Posted: Wed Dec 26, 2012 10:54 am
by haosmark
Thank you, it works now.

Re: $this->config->get not working for me

Posted: Mon Dec 31, 2012 6:23 am
by straightlight
A small correction to the above regarding $this->config->get(); get() is not a function but rather a method being called from system/library/config.php file.

Re: $this->config->get not working for me

Posted: Mon Dec 31, 2012 3:27 pm
by rph
That's splitting hairs a bit. A method is just a function in OOP.

Re: $this->config->get not working for me

Posted: Mon Dec 31, 2012 10:52 pm
by Johnathan
I just called it a function because if you look in the /system/library/config.php file, it says public function get(). :)

Re: $this->config->get not working for me

Posted: Mon Dec 31, 2012 11:32 pm
by straightlight
Yes, I understand. Although, the identification from the class is called a function but the nature of this function is called a method since it is amongst a constructor.