Created
February 9, 2015 01:49
-
-
Save markstory/8f1d4e24a3d0609ad79d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(). | |
* | |
* @var array | |
*/ | |
protected $_accessible = [ | |
'email' => true, | |
'password' => true, | |
'bookmarks' => true, | |
'profile' => true, | |
]; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Model\Table; | |
use Cake\ORM\Query; | |
use Cake\ORM\Table; | |
use Cake\Validation\Validator; | |
/** | |
* Users Model | |
*/ | |
class UsersTable extends Table | |
{ | |
/** | |
* Initialize method | |
* | |
* @param array $config The configuration for the Table. | |
* @return void | |
*/ | |
public function initialize(array $config) | |
{ | |
$this->table('users'); | |
$this->displayField('id'); | |
$this->primaryKey('id'); | |
$this->addBehavior('Timestamp'); | |
$this->hasMany('Bookmarks', [ | |
'foreignKey' => 'user_id', | |
]); | |
$this->hasOne('Profiles', [ | |
'foreignKey' => 'user_id', | |
]); | |
} | |
/** | |
* Default validation rules. | |
* | |
* @param \Cake\Validation\Validator $validator | |
* @return \Cake\Validation\Validator | |
*/ | |
public function validationDefault(Validator $validator) | |
{ | |
$validator | |
->add('id', 'valid', ['rule' => 'numeric']) | |
->allowEmpty('id', 'create') | |
->add('email', 'valid', ['rule' => 'email']) | |
->requirePresence('email', 'create') | |
->notEmpty('email') | |
->add('email', 'unique', ['rule' => 'validateUnique', 'provider' => 'table']) | |
->requirePresence('password', 'create') | |
->notEmpty('password') | |
->allowEmpty('dob') | |
->add('dob', 'valid', ['rule' => 'date']); | |
return $validator; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment