I have created a module in drupal 8 . I need to use a class which is in external file .
File name : drupal.php
Class name : class newman{...}
In drupal.php ( have many classes ):
<?php
namespace Drupal\mymodulename\lib;
class newman{
public function new(){
$dp = 'TEST';
return $dp;
}
}
?>
In my controller :
<?php
namespace Drupal\mymodulename\Controller;
use Drupal\Core\Controller\ControllerBase;
use Drupal\mymodulename\lib\drupal;
class mmController extends ControllerBase {
public function man() {
$this->man=new newman();
$build['test'] = [
'#markup' => $man->new(),
];
}
}
Error: Class 'Drupal\mymodulename\Controller\newman' not found in Drupal...
How can I fix it ?
drupal
/ filenamedrupal.php
.use Drupal\mymodulename\lib\drupal;
which is telling PHP to use theDrupal\mymodulename\lib\drupal
class, which is not the class you first defined. And since you aren't using ause
statement for thenewman
class, PHP doesn't know what class you are trying to use.