【发布时间】:2015-11-24 04:39:41
【问题描述】:
我正在按照教程介绍 Phalcon,一个 php 框架:https://docs.phalconphp.com/en/latest/reference/tutorial-rest.html
我遇到了这个问题:我在下面的代码中有这个错误
类机器人必须声明为抽象或实现方法 'getConnectionService()、setForceExists() 等..'
<?php
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Message;
use Phalcon\Mvc\Model\Validator\Uniqueness;
use Phalcon\Mvc\Model\Validator\InclusionIn;
class Robots extends Model{
public function validation()
{
// Type must be: droid, mechanical or virtual
$this->validate(
new InclusionIn(
array(
"field" => "type",
"domain" => array(
"droid",
"mechanical",
"virtual"
)
)
)
);
// Robot name must be unique
$this->validate(
new Uniqueness(
array(
"field" => "name",
"message" => "The robot name must be unique"
)
)
);
// Year cannot be less than zero
if ($this->year < 0) {
$this->appendMessage(new Message("The year cannot be less than zero"));
}
// Check if any messages have been produced
if ($this->validationHasFailed() == true) {
return false;
}
}
}
?>
即使我尝试执行 HTTP 请求,我也会得到:
无法实例化抽象类 Robots
有什么想法吗?
【问题讨论】:
-
添加:使用Phalcon\Mvc\Model;在声明类之前。
-
是的,对不起,我省略了那部分。上传了,问题依旧。
-
您是否在下一个教程步骤中定义了数据库连接服务?
-
是的。我认为这是 phalcon 和 phpStorm 之间的配置问题。包括在路径 phalcon-tools/ide/2.0.7 而不是 phalcon-tools/ide/phpStorm 一切正常..