While installing a custom module i am getting error

by Bandita Pattanaik   Last Updated August 14, 2019 08:07 AM

While installing a custom module i am getting error: ReflectionException: Class \Drupal\drupalup_json_api\Controller\APITestController does not exist in ReflectionMethod->__construct() (line 136 of D:\xampp1\htdocs\test_my_drupal\core\lib\Drupal\Core\Entity\EntityResolverManager.php).

I cannot know where is the problem ,could anyone help me to fix this?

My controller file

D:\xampp1\htdocs\my_drupal\modules\drupalup_json_api\src\Controller\APITestController

namespace Drupal\drupalup_json_api\Controller;

use Symfony\Component\HttpFoundation\JsonResponse;

// APITest Controller class

class APITestController {

public function renderApi() {

    $category_array = $this->getResults();
    return $category_array;

// print_r($response); // exit; // return $response; /* return new JsonResponse( [ 'data' => $this->getResults(), 'method' => GET, ] ); */ }

private function getResults() {

       $nidlist = array();
    $query = \ Drupal :: database()->select('node_field_data', 'nfd');
    $query->addField('nfd', 'nid');
    $query->condition('nfd.status', 1);
    $query->fields('nfd', ['title']);
    $query->condition('nfd.type', 'user_group');
    $result = $query->execute()->fetchAll();
    print_r($result);
    exit;
    $count = count($result);

    if ($count > 0) {

        foreach ($result as $usergroup) {


            $nidlist[] = array(
                'id' => $usergroup->nid,
                'title' => $usergroup->title,
            );

        }
       echo "<pre>";
        $response = new JsonResponse();
        $response->setContent(json_encode($nidlist, JSON_PRETTY_PRINT));
    } else {
        $message = [
            'text' => 'No Saved items',
        ];
       echo "<pre>";
        $response = new JsonResponse();
        $response->setContent(json_encode($message, JSON_PRETTY_PRINT));
    }
    $response->headers->set('Content-Type', 'application/json');
    return $response;
}
    /*   return [
      [
      "name" => "The Shashank Redemption",
      "year" => 1994,
      "duration" => 42,
      ],
      [
      "name" => "The Godfather ",
      "year" => 1883,
      "duration" => 45,
      ],
      [
      "name" => "The type history ",
      "year" => 1883,
      "duration" => 890,
      ],
      [
      "name" => "The tttt",
      "year" => 1765,
      "duration" => 890,
      ],
      [
      "name" => "The hakuna makata",
      "year" => 1765,
      "duration" => 890,
      ],
      ]; */

}

My routing file

D:\xampp1\htdocs\my_drupal\modules\drupalup_json_api\drupalup_json_api.routing.yml

drupalup_json_api.json_api: path: '/api/json' defaults: _controller: '\Drupal\drupalup_json_api\controller\APITestController::renderApi' _title: 'JSON API' requirements: _access: "TRUE"

and my drupalup_json_api.info.yml

name: 'Drupal UP JSON API' description: 'A simple json api example' type: module core: 8.x

Tags : blocks


Related Questions


Updated March 26, 2015 13:02 PM

Updated April 04, 2015 18:03 PM

Updated April 06, 2015 22:03 PM

Updated March 29, 2015 06:02 AM

Updated April 22, 2015 02:03 AM