0
votes

I'm writting a plugin for Joomla (first time working with Joomla) and I'm having a bit of trouble with something.

Basically what I need is a function in the plugin that returns an url that depends on the plugin parameters. I want to be able to call this function from the site's code like this:

<a href="<?php echo plgSystemMyplugin::get_home_url(); ">access</a>

and my function looks like this:

public function get_home_url () {
    $dn = $this->params->getValue('domainname');
    return 'https://'.$dn.'.mydomain.com';
}

but it returns:

https://.mydomain.com

Any help is appreciated, Thanks in advance

EDIT:

Was able to get around it (not sure if its the right way or not but at this point I just want to get it done).

public function get_home_url () {
    $plg = JPluginHelper::getPlugin('system', 'myplugin');
    $plg_params = new JRegistry();
    $plg_params->loadString($plg->params);
    $dn = $plg_params->get('domainname');
    return 'https://'.$dn.'.mydomain.com';
}
1
Do a var_dump($this->params) and figure out why it's not pulling your domain name through is all I can suggest - basic debugging. - Jimbo

1 Answers

0
votes

That is a static (belonging to class) call:

plgSystemMyplugin::get_home_url();

So

public function get_home_url() 

is not accessible this way (because it belongs to instance).

If you make it static as:

public static function get_home_url() 

then you can not access $this in get_home_url().

Because, $this is one of the dynamic instances not the static class.

Please stop mixing static and dynamic calls and properties.