Welcome Guest, Not a member yet? Register   Sign In
Need to call object in config file
#1

[eluser]RJ[/eluser]
Hello,

I need to call an object in a config file for specific validation rules. System wont let me I get two errors:
Quote:Message: Undefined property: CI_Loader::$dealer
Quote:Message: Trying to get property of non-object

On this code:
Code:
$config = array(
                    'shop/device/'.$this->dealer->dealer.'' => array(
                            array (
                         'field'   => 'country',
                         'label'   => 'lang:country',
                         'rules'   => 'trim|required'
                    ),

Any thoughts on how to accomplish?

Thanks
#2

[eluser]RJ[/eluser]
Program working with:

Code:
$config = array(
                    'device' => array(
                     array (
                         'field'   => 'country',
                         'label'   => 'lang:country',
                         'rules'   => 'trim|required'
                    ),

// and

if ($this->form_validation->run('device') == FALSE)

The question still stands out of curiosity.

Thanks!
#3

[eluser]kgill[/eluser]
The answer is in your error messages:

Code:
Message: Undefined property: CI_Loader::$dealer

Message: Trying to get property of non-object

The loader says dealer doesn't exist, so $this->dealer isn't a viable option, which leads to the 2nd error if $this->dealer isn't there then you can't get the property $this->dealer->dealer because no object exists with that name.

If you had a library/model/whatever named dealer it wasn't loaded before you tried to access it.
#4

[eluser]RJ[/eluser]
I should have mentioned, I had
Code:
global $dealer;
set before, that should have called into config file I would think. Guess not, maybe have to initiate a new object in the config file
#5

[eluser]kgill[/eluser]
$dealer is not the same as $this->dealer, when you use global like that you're defining a variable that exists outside of the class inside your function and so it needs to be referenced as a local variable. When you throw in the keyword this, you're working with something that's part of the the CI super object.
#6

[eluser]TheFuzzy0ne[/eluser]
Also, with working with a class, you have a container to keep all of your class related variables. I'd recommend avoiding any use of the global keyword, as it's not really necessary, and it's pointless cluttering the global scope with variables that don't need to be there.
#7

[eluser]RJ[/eluser]
Good stuff, thanks guys!




Theme © iAndrew 2016 - Forum software by © MyBB