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

Community guidelines

Please keep discussions civil and on-topic. Repeated violations may lead to a temporary ban.

General

Error - Class 'Grav\Plugin\DOMDocument' not found

Solved by Tony Shaw View solution

Started by Tony Shaw 3 years ago · 2 replies · 276 views
3 years ago

I am new to custom plugin creation (per the Plugin Tutorial) and I have a problem. My custom GRAV plugin throws a fatal PHP error:

TXT
Error
Class 'Grav\Plugin\DOMDocument' not found

when I attempt to create (and use) the following:

PHP
<?php
namespace Grav\Plugin;

use Composer\Autoload\ClassLoader;
use Grav\Common\Plugin;

/* SEE: https://learn.getgrav.org/16/plugins/plugin-tutorial */
use Grav\Common\Page\Collection;
use Grav\Common\Uri;
use Grav\Common\Taxonomy;
/* use Grav\Common\Event; */

use Grav\Common\Page\Page;
use RocketTheme\Toolbox\Event\Event;
use RocketTheme\Toolbox\File\File;
use Thunder\Shortcode\Shortcode\ShortcodeInterface;

use ReflectionProperty;

class MyCustomPlugin extends Plugin
{
    public function onFormProcessed(Event $event)
    {
      ...
      $dom = new DOMDocument();
      ...
    }
}

even though 'dom' and 'mbstring' appear to be loaded extensions (apache 2.4.51, php 7.4.26, win10) as shown below:

BASH
-- PHP Loaded Extensions
 With function get_loaded_extensions()

 bcmath        bz2           calendar      com_dotnet    Core          ctype        
 curl          date          **dom**           exif          fileinfo      filter       
 gd            gettext       gmp           hash          iconv         imap         
 intl          json          ldap          libxml        **mbstring**      mysqli       
 mysqlnd       openssl       pcre          PDO           pdo_mysql     pdo_sqlite   
 Phar          readline      Reflection    session       SimpleXML     soap         
 sockets       SPL           sqlite3       standard      tokenizer     xdebug       
 xml           xmlreader     xmlrpc        xmlwriter     xsl           Zend OPcache 
 zip           zlib         

Is there a use ... statement that would solve my (fatal) php problem/error?

3 years ago

What if you try this?

PHP
$dom = new \DOMDocument();
3 years ago Solution

Thank for trying to help!

In Visual Studio Code I searched for the term “domDocument” in the GRAV plugins directory and found other plugins’ main php file with:

use domDocument;

above the class definition. Adding this to my main php page solved my problem.

Suggested topics

Topic Participants Replies Views Activity
General · by Jerry Hunt, 4 days ago
2 82 11 hours ago
General · by pamtbaau, 17 hours ago
1 55 16 hours ago
General · by Andy Miller, 1 day ago
0 45 1 day ago
General · by Marcel, 12 months ago
6 348 5 days ago
General · by Duc , 5 days ago
3 43 5 days ago