我需要使用Customizing Find Query对CakePHP 3.4中的身份验证进行身份验证。我遵循了烹饪书,但在我的findAuth
方法中$option
返回空array
。我不知道代码中的错误是什么。
public function initialize()
{
parent::initialize();
$this->loadComponent('RequestHandler');
$this->loadComponent('Auth', [
'authenticate' => [
'Form' => [
'finder' => 'auth',
'fields' => ['username' => 'username', 'password' => 'password']
]
],
]);
}
UsersTable.php
public function findAuth(\Cake\ORM\Query $query, array $options)
{
debug($options);
$query->select(['sno', 'username', 'password','contact'])
->where(['Users.username' => $options['username']]);
return $query;
}
login.ctp
<?php
echo $this->Form->create();
echo $this->Form->input('username');
echo $this->Form->input('password');
echo $this->Form->submit();
echo $this->Form->end();
?>
答案 0 :(得分:0)
//group list entries to sub - lists having the same effect value
Map<String, List<Item>> map = itemList.stream()
.collect(Collectors.groupingBy(Item::getEffect)) ;
List<Item> uniqueEfectMaxValue = new ArrayList<>();
//get item having max value and add to uniqueEfectMaxValue
map.forEach((key,list)->{
Item item = list.stream().
collect(Collectors.maxBy(Comparator.
comparing(Item::getValue))).get();
uniqueEfectMaxValue.add(item);
}
);
应为:
public function findAuth(\Cake\ORM\Query $query, array $options)
{
debug($options);
$query->select(['sno', 'username', 'password','contact'])
->where(['Users.username' => $options['username']]);
return $query;
}