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

Classes not found

Hi all, I have a problem with this simple code below.

 $application->post('/group/', function() use ($application){

 // Get Json
 $group = $application->request->getJsonRawBody();

 $query = "INSERT INTO Group (group_name) VALUES (:group_name:)";

 $status = $application->modelsManager->executeQuery($query,array(
           'group_name' => $group->group_name  // #### FIRST WARNING
 ));

 $response = new Response();

 if ($status->success() == true){                    //#### SECOND WARNING
            $response->setStatusCode(201, "Created");
 } else {
            $group->id = $status->getModel()->id;   //#### THIRD WARNING
           $response->setJsonContent(array(
               'status' => 'OK',
               'data'   => $group
           ));
 }
});

There are exactly three warnings:

  1. Field group_name not found in class bool
  2. Method success not found in class Mvc/Model/Query
  3. Method getModel not found in class Mvc/Model/Query

I don't know if I have installation or configuration problems with phalcon or phpstorm but this problem joins the one I posted yesterday here: https://forum.phalcon.io/discussion/8269/model-class-must-be-declared-abstract

edited Aug '15

1 - var_dump($application->request->getJsonRawBody()), are you sure there are group_name in this object ? if not then you know why you have this warning, also i pref on working on array instead of object so do $application->request->getJsonRawBody(true)

2 and 3 - https://docs.phalcon.io/pl/latest/api/Phalcon_Mvc_Model_Query.html this class just dont have those methods, so i dont know why are you trying to call them

1 - var_dump($application->request->getJsonRawBody()), are you sure there are group_name in this object ? if not then you know why you have this warning, also i pref on working on array instead of object so do $application->request->getJsonRawBody(true)

Yes, it helped!

2 and 3 - https://docs.phalcon.io/pl/latest/api/Phalcon_Mvc_Model_Query.html this class just dont have those methods, so i dont know why are you trying to call them

I'm just studing tutorials, I found it here: https://docs.phalcon.io/en/latest/reference/tutorial-rest.html#inserting-data

edited Aug '15

From Phalcon 2.0.x there are no longer Phalcon\Mvc\Model\Query\Status class which had those methods, from now it should return just boolean value true/false, so only if($status) should be enough i guess.

That isn't true: https://github.com/phalcon/cphalcon/blob/2.0.x/phalcon/mvc/model/query/status.zep

From Phalcon 2.0.x there are no longer Phalcon\Mvc\Model\Query\Status class which had those methods, from now it should return just boolean value true/false, so only if($status) should be enough i guess.

Oh i missed it in api :D So i dont know why its not working.