简体   繁体   English

Phalcon MVC模型异常

[英]Phalcon MVC model Exception

I'm trying to create an API with Phalcon for the first time. 我正在尝试首次使用Phalcon创建API。 I have been followed the tutorial " http://docs.phalconphp.com/en/latest/reference/tutorial-rest.html ", but encountered a problem. 我已经按照教程“ http://docs.phalconphp.com/en/latest/reference/tutorial-rest.html ”进行操作,但是遇到了问题。 I've been created a new project with all the settings, and inside I got: 我已经使用所有设置创建了一个新项目,并且在其中得到了:

  1. a "models" folder with "photos.php" file 带有"photos.php"文件的"models"文件夹
  2. a "index.php" with connection to my DB and function to retrieve information from "photos" table 连接到我的数据库的"index.php" ,并具有从“照片”表中检索信息的功能

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 in “ Phalcon \\ Mvc \\ Model \\ Exception:无法将模型“照片”加载到 C:\\wamp\\www\\Test\\index.php on line 77". C:\\ wamp \\ www \\ Test \\ index.php行77“。

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

What can cause this problem? 什么会导致此问题?

It's one of three problems: 这是三个问题之一:

1 - Your class name in photos.php is not photos. 1-您在photos.php中的班级名称不是照片。

2 - You have mis-referenced the photos model in your PHQL query. 2-您在PHQL查询中错误引用了照片模型。

3 - You have not registered the directory where your models are stored. 3-您尚未注册存储模型的目录。 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();

If you create project structure using Phalcon developer tool, the config.ini might need an update like this: 如果使用Phalcon开发人员工具创建项目结构,则config.ini可能需要这样的更新:

from:
modelsDir      = /models/

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

i just faced same issue, got it solved by add require with model path right after $di = new \\Phalcon\\DI\\FactoryDefault(); 我只是面临着同样的问题,在$di = new \\Phalcon\\DI\\FactoryDefault();之后通过添加带有模型路径的require来解决$di = new \\Phalcon\\DI\\FactoryDefault(); and

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

like suggested by brian 像布莱恩建议的那样

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM