user3079839
user3079839

Reputation: 1

Phalcon MVC model Exception

I'm trying to create an API with Phalcon for the first time. I have been followed the tutorial "http://docs.phalconphp.com/en/latest/reference/tutorial-rest.html", but encountered a problem. I've been created a new project with all the settings, and inside I got:

  1. a "models" folder with "photos.php" file
  2. a "index.php" with connection to my DB and function to retrieve information from "photos" table

The problem is that when I'm trying to activate the function through the browser i get an Error:

"Phalcon\Mvc\Model\Exception: Model 'photos' could not be loaded inC:\wamp\www\Test\index.php on line 77".

$photos = $app->modelsManager->executeQuery($phql); // line 77

What can cause this problem?

Upvotes: 0

Views: 3196

Answers (3)

user3743879
user3743879

Reputation: 11

i just faced same issue, got it solved by add require with model path right after $di = new \Phalcon\DI\FactoryDefault(); and

before $app = new \Phalcon\Mvc\Micro($di);

like suggested by brian

Upvotes: 0

user3781275
user3781275

Reputation: 1

If you create project structure using Phalcon developer tool, the config.ini might need an update like this:

from:
modelsDir      = /models/

to:
modelsDir      = **..**/models/

Upvotes: 0

brian
brian

Reputation: 2775

It's one of three problems:

1 - Your class name in photos.php is not photos.

2 - You have mis-referenced the photos model in your PHQL query.

3 - You have not registered the directory where your models are stored. To do this, add

$loader = new \Phalcon\Loader();
$loader->registerDirs(array(
    '/path/to/models'
))->register();

after

$di = new \Phalcon\DI\FactoryDefault();

but before

$app = new \Phalcon\Mvc\Micro();

Upvotes: 1

Related Questions