Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Tutorial 3: REST API

Hi guys, I'm a newbie here. I've tried Tutorial 3: Creating a Simple REST API and got stucked at the end of the tutorial. While I'm sending any reqeuest with curl, I'm always getting an Internal server error (500). I don't have any idea what I'm doing wrong.

Source code can be found here.

Can anybody help me? Thanks a lot!



3.7k
Accepted
answer

Hi,

You have syntax error in these lines:

L24:        
return new \Phalcon\Db\Adapter\Pdo\Mysql\(array(
Correct:
return new \Phalcon\Db\Adapter\Pdo\Mysql(array(
...
L168-L173:
$status = $app->modelsManager->executeQuery($phql, array(
        'id' = $id,
        'name' = $robot->name,
        'type' = $robot->type,
        'year' = $robot->year
));
Correct:
$status = $app->modelsManager->executeQuery($phql, array(
        'id' => $id,
        'name' => $robot->name,
        'type' => $robot->type,
        'year' => $robot->year
));
...
L210:
$status = $app->modelsManager->executeQuery($phql, array(
    'id' = $id
));
Correct
$status = $app->modelsManager->executeQuery($phql, array(
    'id' => $id
));

After fix these lines your REST API should works.

How did you get it? Which tool are you using? I didn't get anything. But thanks!

edited Jul '14

Heh, normally :) I open your project by browser. Probably your php settings don't shows errors even with error_reporting(E_ALL). Check are you have display_errors On in your php.ini

Damn, you were right! Shame on me... :D

Hi please can you tell me where to place the 'the return new" I am having an error saying " Trying to get property of non-object"

Hi,

You have syntax error in these lines:

```php L24:
return new \Phalcon\Db\Adapter\Pdo\Mysql(array( Correct: return new \Phalcon\Db\Adapter\Pdo\Mysql(array( ... L168-L173: $status = $app->modelsManager->executeQuery($phql, array( 'id' = $id, 'name' = $robot->name, 'type' = $robot->type, 'year' = $robot->year )); Correct: $status = $app->modelsManager->executeQuery($phql, array( 'id' => $id, 'name' => $robot->name, 'type' => $robot->type, 'year' => $robot->year )); ... L210: $status = $app->modelsManager->executeQuery($phql, array( 'id' = $id )); Correct $status = $app->modelsManager->executeQuery($phql, array( 'id' => $id )); ```

After fix these lines your REST API should works.