...

View Full Version : How to access these



hailwood
05-28-2010, 04:32 PM
hi guys,

I need to know how to access these

if im doing this:


$this->config = Config::getInstance();


print_r($this->config);



and its spitting out:





Config Object
(
[base] => Array
(
[abs_path] => C:/server/xampp/htdocs/***/
[url_path] => http://localhost/***/
[temp_dir] => tmp/
[env] => dev
)


[database] => Array
(
[host] => localhost
[user] => root
[pass] =>
[name] => ***
)


[mconnect] => Array
(
[url=http://=> ***
[appname] => ***
[password] => ***
[msgclass] => ***
)


[interfax] => Array
(
=> ***
[username] => ***
[password] => ***
[filetype] => HTML
)


)

so what goes in place of this question mark if i want to get the database name?
$this->config->?


Ive tried $this->config->database['name'];


but i get cannot access empty property

so what goes in place of this question mark if i want to get the database name?
$this->config->?


Ive tried $this->config->database['name'];


but i get cannot access empty property

Fou-Lu
05-28-2010, 04:39 PM
Those are listed as array datatypes. You can access it with $this->config['database']['name'];.

hailwood
05-28-2010, 05:13 PM
Thats what i thought,

but its not working, here is the current status:

Attempt: $this->config->database['name'];
Error: cannot access empty property

Attempt: $this->config->database->name;
Error: cannot access empty property

Attempt: $this->config[database][name];
Error: Cannot use object of type Config as array

Attempt: $this->config->[database][name];
Error: Incorrect Syntax

Fou-Lu
05-28-2010, 06:50 PM
Oh yeah sorry that print_r is on $this->config not $this. So yes, that would be $this->config->database['name'].

What does this give you:


ReflectionObject::export($this->config);

?

The actual errors themselves indicate that 'database' is an invalid property of the config instance, or that config is an invalid property of this. You are 100% certain that you have that in there (as in, something like:


class Config
{
public $database;
//...
public function __construct(/*..*/)
{
$database = array();
//..
}
//..
}

)? To use it in the context you have, you must have these as public members (though that is not the error you are receiving, the error is indicating that they just do not exist).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum