CakeDC\Users\Model\Table\UsersTable::initialize PHP Метод

initialize() публичный Метод

Initialize method
public initialize ( array $config ) : void
$config array The configuration for the Table.
Результат void
    public function initialize(array $config)
    {
        parent::initialize($config);
        $this->table('users');
        $this->displayField('username');
        $this->primaryKey('id');
        $this->addBehavior('Timestamp');
        $this->addBehavior('CakeDC/Users.Register');
        $this->addBehavior('CakeDC/Users.Password');
        $this->addBehavior('CakeDC/Users.Social');
        $this->hasMany('SocialAccounts', ['foreignKey' => 'user_id', 'className' => 'CakeDC/Users.SocialAccounts']);
    }

Usage Example

Пример #1
0
 /**
  * Initialize method
  *
  * @param array $config The configuration for the Table.
  * @return void
  */
 public function initialize(array $config)
 {
     parent::initialize($config);
     $this->table('members');
     $this->belongsToMany('Teams', ['through' => 'TeamMemberships', 'dependent' => true]);
     $this->belongsToMany('Games', ['through' => 'GameMemberships', 'dependent' => true]);
     //        $this->belongsToMany('Tos',
     //            [
     //                'through' => 'Friendships',
     ////                'joinTable'=>'Friendships',
     ////                'foreignKey'=>'id',
     //                'foreignKey'=>'to_id',
     //                'className'=>'Members',
     ////                'queryBuilder' => function (Query $q) {
     ////                    return $q->where(['Friends.from_id == Members.id']); // Full conditions for filtering
     ////                }
     //            ]
     //        );
     //        $this->belongsToMany('Froms',
     //            [
     //                'through' => 'Friendships',
     ////                'joinTable'=>'Friendships',
     ////                'foreignKey'=>'id',
     //                'targetForeignKey'=>'from_id',
     //                'className'=>'Members',
     ////                'queryBuilder' => function (Query $q) {
     ////                    return $q->where(['Friends.from_id == Members.id']); // Full conditions for filtering
     ////                }
     //            ]
     //        );
     $this->addBehavior('Search.Search');
     //        $this->addBehavior('CounterCache', [
     //            'Friends' => [
     //                'friend_count' => function (Event $event, Entity $entity, Table $table) {
     //                    $query = $table->find('all')->where([
     //                        'to_id' => $entity->get('id')
     //                    ])->orWhere(['from_id'=>$entity->get('id')]);
     //                    return $query->count();
     //                }
     //            ]
     //        ]);
     //
     $this->searchManager()->add('q', 'Search.Like', ['before' => true, 'after' => true, 'field' => [$this->aliasField('first_name'), $this->aliasField('last_name')]]);
     $this->isValidateEmail = true;
 }