2015-09-10 61 views
10
<?php 
namespace App\Model\Entity; 

use Cake\ORM\Entity; 

/** 
* User Entity. 
*/ 
class User extends Entity 
{ 

    /** 
    * Fields that can be mass assigned using newEntity() or patchEntity(). 
    * Note that '*' is set to true, which allows all unspecified fields to be 
    * mass assigned. For security purposes, it is advised to set '*' to false 
    * (or remove), and explicitly make individual fields accessible as needed. 
    * 
    * @var array 
    */ 
    protected $_accessible = [ 
     '*' => true, 
     'id' => false, 
    ]; 

    protected function _setPassword($value) 
    { 
     $hasher = new DefaultPasswordHasher(); 
     return $hasher->hash($value); 
    } 
} 

这是我在user.php中的代码。 我散列密码,并得到这样的出错错误:找不到类'App Model Entity DefaultPasswordHasher'

Error: Class 'App\Model\Entity\DefaultPasswordHasher' not found File C:\xamp\htdocs\bookmarker\src\Model\Entity\User.php Line: 27

回答

20

我错过下面一行:

use Cake\Auth\DefaultPasswordHasher; 

这就是为什么我得到了错误的原因。

+0

我得到'错误:语法错误,意外'?' '在那条线上。任何线索? – JackTheKnife

+0

@JackTheKnife检查你的语法。 –