Why Micro did not see the model?

There is action in which I am trying to pull all records from the table:
public function getAccounts() {
 $accounts = Accounts::find();

 return $this->response->setJsonContent(['accounts' => $accounts])->send();
 }


In PostMan gives
<br / >
<b>Warning</b>: class 'AdminController' does not have a method 'Accounts' in
<b>C:\OSPanel\domains\fisher.loc\public\index.php</b> on line
<b>20</b>
<br / >


Although in the loader directory indicated.
It looks like the model itself
<?
use Phalcon\Mvc\Model;

class Accounts extends Model {
 public $id;

 public $login;

 public $password;

}</property-->
br><br> What's the problem?
June 5th 19 at 21:38
2 answers
June 5th 19 at 21:40
Solution
In the loader you need to register the namespace and directory of models

$loader = new \Phalcon\Loader();

$loader->registerNamespaces(
[
 'App\\Models' => __DIR__ . '/models/',
]
);

$loader->registerDirs(
[
...
 __DIR__ . '/models/',
...
]
)->register();


namespace App\Models;

class Accounts extends \Phalcon\Mvc\Model {
 public $id;

 public $login;

 public $password;

 public $steam_guard;

 public $email;

 public $worker_id;
}


use App\Models\Accounts;

class AdminController extends \Phalcon\Mvc\Controller {
 public function getAccounts() {
 $accounts = Accounts::find();

 return $this->response->setJsonContent(['accounts' => $accounts])->send();
}
}
June 5th 19 at 21:42
Solution
$accounts = Accounts::find();
 $this->response->setJsonContent(['accounts' => $accounts])->send();

Did everything as said. The namespace is added.
Just a blank page. Generally emptiness.
But if you remove the reference to the model, the json is sent.
In the PHP log something falls? Mysql query takes?
count($accounts) and var_dump($accounts) try.
Well, the default model returns a StdClass object, you may want to convert to an array:
$this->response->setJsonContent(['accounts' => $accounts->toArray()])->send();
- Jalon_Schaden commented on June 5th 19 at 21:45

Find more questions by tags Phalcon