Ich bin neu in CakePHP, so dass dies eine Anfängerfrage sein kann.Kann Search-Plugin für CakePHP nicht installieren von Friendsofcake
Ich versuche, die Suche Plugin für CakePHP von Friendsofcake (https://github.com/FriendsOfCake/search)
Mit der Readme in den obigen Link zu installieren, ich QANT meine Benutzer suchen durch die Felder E-Mail (varchar) und RG (Ganzzahl).
Aber, wie ich versuche, ../Benutzer zu besuchen, präsentiert das System den Fehler am Ende dieses Textes. Der Fehler scheint zu sein, als ob die Methode findParams nicht gültig ist, auch wenn das Such-Plugin in meine bootstrap.php geladen ist.
Ich habe folgendes UsersTable.php und UsersController.php:
UsersTable:
use Search\Manager;
class UsersTable extends Cake\ORM\Table {
public function initialize(array $config)
{
parent::initialize();
// Add the behaviour to your table
$this->addBehavior('Search.Search');
}
// Configure how you want the search plugin to work with this table class
public function searchConfiguration()
{
$search = new Manager($this);
$search
->value('email', [
'field' => $this->aliasField('email'),
])
// Here we will alias the 'q' query param to search the `Users.email`
// field and the `Users.rg` field, using a LIKE match, with `%`
// both before and after.
->like('q', [
'before' => true,
'after' => true,
'field' => [$this->aliasField('email'), $this->aliasField('rg')]
])
->callback('foo', [
'callback' => function ($query, $args, $manager) {
// Modify $query as required
}
]);
return $search;
}
}
Userscontroller:
namespace App\Controller;
class UsersController extends AppController
{
public function initialize()
{
parent::initialize();
$this->loadComponent('Search.Prg', [
'actions' => ['index']
]);
}
public function login() {
if ($this->request->is('post')) {
$user = $this->Auth->identify();
if ($user) {
$this->Auth->setUser($user);
return $this->redirect($this->Auth->redirectUrl());
}
$this->Flash->error('Your username or password is incorrect.');
}
}
public function logout() {
$this->Flash->success('You are now logged out.');
return $this->redirect($this->Auth->logout());
}
public function index()
{
$query = $this->Users
// Use the plugins 'search' custom finder and pass in the
// processed query params
->find('search', $this->Users->filterParams($this->request->query))
// You can add extra things to the query if you need to
->contain(['rg'])
->where(['email IS NOT' => null]);
$this->set('articles', $this->paginate($query));
}
}
und jetzt bin ich immer die Fehlermeldung:
Unknown method "filterParams" BadMethodCallException
⟩ Cake\ORM\Table->__call APP/Controller\UsersController.php, line 42 ⟩ App\Controller\UsersController->index [internal function] ⟩ call_user_func_array ROOT\vendor\friendsofcake\crud\src\Controller\ControllerTrait.php, line 51 ⟩ App\Controller\AppController->invokeAction CORE\src\Routing\Dispatcher.php, line 114 ⟩ Cake\Routing\Dispatcher->_invoke CORE\src\Routing\Dispatcher.php, line 87 ⟩ Cake\Routing\Dispatcher->dispatch ROOT\webroot\index.php, line 36