1
我有以下作曲家文件:Symfony驗證程序未加載?
{
"require": {
"doctrine/orm": "2.4.*",
"doctrine/migrations": "1.0.*@dev",
"symfony/validator": "2.8.*@dev",
"slim/slim": "~2.6",
"freya/freya-exception": "0.0.7",
"freya/freya-loader": "0.2.2",
"freya/freya-templates": "0.1.2",
"freya/freya-factory": "0.0.8"
},
"autoload": {
"psr-4": {"": ""}
}
}
我創建了下面的實體,或者我給他們打電話型號:
namespace App\Models;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Validation;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ORM\Entity
* @ORM\Table(name="users")
*/
class User {
/**
* @ORM\Id
* @ORM\Column(type="integer")
* @ORM\GeneratedValue
*/
protected $id;
/**
* @ORM\Column(type="string", length=32, nullable=false)
*/
protected $firstName;
/**
* @ORM\Column(type="string", length=32, nullable=false)
*/
protected $lastName;
/**
* @ORM\Column(type="string", length=100, unique=true, nullable=false)
*/
protected $userName;
/**
* @ORM\Column(type="string", length=100, unique=true, nullable=false)
* @Assert\Email
*/
protected $email;
/**
* @ORM\Column(type="string", length=500, nullable=false)
*/
protected $password;
...
}
現在,當我運行"vendor/bin/doctrine" migrations:diff
我得到一個錯誤:
[Doctrine\Common\Annotations\AnnotationException]
[Semantical Error] The annotation "@Symfony\Component\Validator\Constraints\Email" in property App\Models\User::$email does not exist, or could not be auto-loaded.
symfony的文檔沒有說明如何正確設置它,除了github page和t繼承人的實際文件指出,幾乎相同。
那麼,爲什麼我會得到這個錯誤?我看着和類並安裝驗證程序的列表下存在...
這仍然給我帶來同樣的問題。 – TheWebs
您需要'需要':'$ loader = require __DIR__。 '/../ vendor/autoload.php';'確保你的路徑是正確的。 – keyboardSmasher
對不起,我最終刪除了我的回覆,但現在它似乎正在工作 - 或者至少這個調用有效,輸出仍然是一樣的,我需要將這些代碼放在哪個特定位置?像我擁有的或實體中的bootstrap.php? – TheWebs