Mohamed Mazen
Mohamed Mazen

Reputation: 5

TYPO3: Uncaught Error: Class not found any class want to use always give me this error

I am trying to build an extension. In this extension, I'm trying to connect to the database of TYPO3 but I can't access this class and any class is always not found

use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Utility\GeneralUtility;

class rpc {

    /**
     *
     * @var string
     */
    public $tsc_Endpoint = '';

    /**
     *
     * @var string
     */
    public $tsc_tokenID = '';

    /**
     * The main method of the backend module
     */
    public function main(){
        $connection = GeneralUtility::makeInstance(
            ConnectionPool::class)
            ->getConnectionForTable('gpi_configurations');

        $queryBuilder = $connection->createQueryBuilder();
        $query = $queryBuilder
            ->select('*')
            ->from('gpi_configurations')
            ->where('config_name = tsc_Endpoint');

        $rows = $query->execute->fetchRows();
        print_r($rows);


        $client = GeneralUtility::makeInstance(GpiClient::class);
        try {
            $server = GeneralUtility::makeInstance(JsonRpc::class)->__construct($client);
        } catch (\Exception $e) {
        }
        echo  $server->process();

    }


}

    $q = new rpc();
    $q->main();

I want to mention something this bulk of code in a file called rpc.php

Is there a way to access TYPO3 functionality on rpc.php? I did many searches but I did not find any useful help.

installing structure

Upvotes: 0

Views: 1296

Answers (1)

nito
nito

Reputation: 1313

Full edit:

From our conversation below, I think what you need is a Middleware to provide an endpoint. This endpoint reads data from the TYPO3-database passes them your your rpc-service and returns some JSON as $response.

  • To ensure autoloading, all your PHP-code should go into the Classes/ folder.
  • You have to use namespace Mazen\YourExtensionName\... in your Classes.
  • I would recommend to make your rpc-class a service and put it into Classes/Service/ but I might not know enough about your application.
  • Read the Docs about TYPO3 Doctrine, especially the part about the WHERE clause.
  • Reading and learning some basic priceless about TYPO3 Extension Development might be a good idea.

Middleware

Doctrine

Services

The Service API it self is deprecated, but you still can group some parts of your application into service ans load them with Dependency Injection from everywhere you need them.

TYPO3 Extension Development

Upvotes: 1

Related Questions