Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Require class into custom plugin

Started by Muut Archive 10 years ago · 1 replies · 534 views
10 years ago

Hi all.Need some help with including my own class into custom plugin.When I load the page, I have an error "Class 'Grav\Plugin\MCAPI' not found" .Please help how to fix it.Thanks before

PHP

<?
namespace Grav\Plugin;
use Grav\Common\Plugin;
use Grav\Common\Twig\Twig;
use RocketTheme\Toolbox\Event\Event;
class ExamplePlugin extends Plugin
{
public static function getSubscribedEvents()
{
return [
‘onPluginsInitialized’ => ['onPluginsInitialized', 0],
‘onTwigExtensions’ => ['onTwigExtensions', 0],
‘onFormProcessed’ => ['onFormProcessed', 0]
];
}
public function onTwigExtensions()
{ 
requireonce(DIR_ . /twig/ExampleTwigExtension.php’);
$this->grav['twig']->twig->addExtension(new ExampleTwigExtension());
}
public function onPluginsInitialized()
{
if ($this->config->get('plugins.example.enabled')) {
$this->enable([
‘onTwigSiteVariables’ => ['onTwigSiteVariables', 0]
]);
}
}
public function onTwigSiteVariables()
{
requireonce DIR_ . /classes/MCAPI.class.php’;
$twig = $this->grav['twig'];
//need something write here.
}
}
?>
10 years ago

Since you define the namespace namespace Grav\Plugin, if you try to call your class as MCAPI the namespace is prepended to it. Try \MCAPI

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1370 9 years ago
Archive · by Muut Archive, 9 years ago
2 943 9 years ago
Archive · by Muut Archive, 9 years ago
2 4069 9 years ago
Archive · by Muut Archive, 9 years ago
1 2960 9 years ago
Archive · by Muut Archive, 9 years ago
3 1127 9 years ago