tonic
tonic copied to clipboard
New class not loaded
Hi, I am using Respond CMS that uses tonic RESTful. I am trying to add a new class in the rest directory. But this class cannot be loaded. I run the following code
require_once '../vendor/peej/tonic/src/Tonic/Autoloader.php';
$app = new Tonic\Application(); $request = new Tonic\Request();
require_once 'myclass.php';
$resource = $app->getResource($request); $response = $resource->exec(); $response->output();
The class was not loaded, I got error 'Tonic\NotFoundException'. Any help would be appreciated.
Regards guilan
Tonic requires that resource classes are already loaded so that it can reflect upon them. You either need to require your class before instantiating Tonic\Application, or get Tonic to require resources for you by using the "load" configuration option.
I also run this script:
require_once '../vendor/peej/tonic/src/Tonic/Autoloader.php'; $app = new Tonic\Application(array( 'load' => 'myclass.php' )); $request = new Tonic\Request(); $resource = $app->getResource($request); $response = $resource->exec(); $response->output(); echo "load myclass";
The script failed at the line: $resource = $app->getResource($request);
Any idea why the resource cannot be got?
Having drilled down from Application.php and found the failure occurred at the line 236: $docComment = $this->parseDocComment($classReflector->getDocComment()); getDocComment reads uri from the comments on the top of the class. I didn't copy this comments. I didn't know the comments are so vital in PHP, which is not normal concept. I added the comment /* @uri /myclass/test */. Now myclass is working OK.