We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

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!



5.2k
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.



1.0k

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



1.0k

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:

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.