Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New class not loaded #189

Open
guilanh opened this issue Mar 27, 2015 · 3 comments
Open

New class not loaded #189

guilanh opened this issue Mar 27, 2015 · 3 comments

Comments

@guilanh
Copy link

guilanh commented Mar 27, 2015

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

@peej
Copy link
Owner

peej commented Mar 29, 2015

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.

@guilanh
Copy link
Author

guilanh commented Mar 31, 2015

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?

@guilanh
Copy link
Author

guilanh commented Mar 31, 2015

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants