1

My plugin structure was created by the plugin factory. I have a setting called ulStateClass and I have been able to change the value of that setting in the Setting for the plug in. Looking at the 3.0 Docs page for settings I see the example:

// From your main plugin class:
$foo = $this->getSettings()->foo;

// From elsewhere:
$foo = \ns\prefix\Plugin::getInstance()->getSettings()->foo;

My namespace is recoveryfinder\craftnav

In my services php file I have the following to test:

echo \recoveryfinder\craftnav::getInstance()->getSettings()->ulStateClass;

I am getting the error:

Error Class 'recoveryfinder\craftnav' not found

Making progress with Craft and enjoying it. I am guessing that this is a misuse or misunderstanding of namespaces? How Do I correct this?

3

Little bit confused with your question, if you want to access your settings then you can do craft::$app->plugins->getPlugin('handle')->getSettings()->foo;

  • That worked but is very different than the 3.0 docs that I reference. – Eric Snyder Mar 26 '18 at 3:52
  • If you are calling that method from elsewhere page then you use namespace else you will be using the one that i provided. – sailendra mangranti Mar 26 '18 at 5:00
  • Note: this solution is the slower, performance worse one, that calls the ns\prefix\Plugin::getInstance()->getSettings() in the end. I suggest to download a proper IDE that handles all namespaces and includes for you and aceess the plugin directly. – Robin Schambach Mar 26 '18 at 5:14
  • I am using Netbeans. I am editing the plugin locally and running a LAMP server on my laptop. When I test my code I refresh the page in the browser from my local machine. The code ns\prefix\Plugin::getInstance()->getSettings()->ulStateClass; or recoveryfinder\craftnav::getInstance()->getSettings()->ulStateClass; was not working from my local machine server. – Eric Snyder Mar 26 '18 at 11:30
  • @robin-schamback I said I was using Netbeans. I suppose I should have said I was abusing Netbeans :)! What do you recommend? – Eric Snyder Mar 26 '18 at 23:06
1

Try

\recoveryfinder\craftnav\Craftnav::getInstance()->getSettings()->ulStateClass;

Assuming your main plugin file/class is Craftnav.php

Hope this helps :)

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.