FriendsOfCake / search

CakePHP: Easy model searching
MIT License
170 stars 59 forks source link

Missing Search.Search behavior on App\Model\Table\VendorsTable #212

Closed karthikeyanangler closed 6 years ago

karthikeyanangler commented 6 years ago

Hi,

I am getting following error with Search Listener.

Missing Search.Search behavior on App\Model\Table\VendorsTable
RuntimeException
Documentation API
If you want to customize this error message, create src\Template\Error\error500.ctp

toggle vendor stack frames
⟩ Crud\Listener\SearchListener->injectSearch
CORE\src\Event\EventManager.php, line 416
⟩ Cake\Event\EventManager->_callListener
CORE\src\Event\EventManager.php, line 393
⟩ Cake\Event\EventManager->dispatch
ROOT\vendor\friendsofcake\crud\src\Controller\Component\CrudComponent.php, line 506
⟩ Crud\Controller\Component\CrudComponent->trigger
ROOT\vendor\friendsofcake\crud\src\Core\ProxyTrait.php, line 37
⟩ Crud\Core\Object->_trigger
ROOT\vendor\friendsofcake\crud\src\Action\IndexAction.php, line 55
⟩ Crud\Action\IndexAction->_handle
[internal function]
⟩ call_user_func_array
ROOT\vendor\friendsofcake\crud\src\Action\BaseAction.php, line 71
⟩ Crud\Action\BaseAction->handle
ROOT\vendor\friendsofcake\crud\src\Controller\Component\CrudComponent.php, line 228
⟩ Crud\Controller\Component\CrudComponent->execute
APP/Controller\Api\VendorsController.php, line 31
⟩ App\Controller\Api\VendorsController->index
[internal function]
⟩ call_user_func_array
ROOT\vendor\friendsofcake\crud\src\Controller\ControllerTrait.php, line 51
⟩ App\Controller\API\AppController->invokeAction
CORE\src\Http\ActionDispatcher.php, line 119
⟩ Cake\Http\ActionDispatcher->_invoke
CORE\src\Http\ActionDispatcher.php, line 93
⟩ Cake\Http\ActionDispatcher->dispatch
CORE\src\Http\BaseApplication.php, line 108
⟩ Cake\Http\BaseApplication->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
CORE\src\Routing\Middleware\RoutingMiddleware.php, line 104
⟩ Cake\Routing\Middleware\RoutingMiddleware->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
CORE\src\Routing\Middleware\AssetMiddleware.php, line 88
⟩ Cake\Routing\Middleware\AssetMiddleware->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
CORE\src\Error\Middleware\ErrorHandlerMiddleware.php, line 98
⟩ Cake\Error\Middleware\ErrorHandlerMiddleware->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
ROOT\vendor\cakephp\debug_kit\src\Middleware\DebugKitMiddleware.php, line 52
⟩ DebugKit\Middleware\DebugKitMiddleware->__invoke
CORE\src\Http\Runner.php, line 65
⟩ Cake\Http\Runner->__invoke
CORE\src\Http\Runner.php, line 51
⟩ Cake\Http\Runner->run
CORE\src\Http\Server.php, line 81
⟩ Cake\Http\Server->run
ROOT\webroot\index.php, line 40

VendorsTable.php

<?php
namespace App\Model\Table;

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

class VendorsTable extends Table
{

    public function initialize(array $config)
    {
        parent::initialize($config);       

        $this->setTable('vendors');
        $this->setDisplayField('name');
        $this->setPrimaryKey('id');

        $this->addBehavior('Timestamp');
        $this->addBehavior('Search.Search');

        $this->hasMany('ForecastMaterials', [
            'foreignKey' => 'vendor_id'
        ]);
        $this->hasMany('Materials', [
            'foreignKey' => 'vendor_id'
        ]);
        $this->hasMany('PurchaseOrders', [
            'foreignKey' => 'vendor_id'
        ]);
        $this->hasMany('VendorBroadcasts', [
            'foreignKey' => 'vendor_id'
        ]);
        $this->hasMany('VendorUsers', [
            'foreignKey' => 'vendor_id'
        ]);
    }

    public function validationDefault(Validator $validator)
    {
        $validator
            ->integer('id')
            ->allowEmpty('id', 'create');

        $validator
            ->scalar('code')
            ->maxLength('code', 12)
            ->requirePresence('code', 'create')
            ->notEmpty('code');

        $validator
            ->scalar('name')
            ->maxLength('name', 75)
            ->requirePresence('name', 'create')
            ->notEmpty('name');

        $validator
            ->scalar('address')
            ->requirePresence('address', 'create')
            ->notEmpty('address');

        $validator
            ->email('email')
            ->allowEmpty('email');

        $validator
            ->scalar('phone')
            ->maxLength('phone', 50)
            ->allowEmpty('phone');

        $validator
            ->scalar('mobile')
            ->maxLength('mobile', 50)
            ->allowEmpty('mobile');

        $validator
            ->allowEmpty('state_code');

        $validator
            ->scalar('gstin')
            ->maxLength('gstin', 50)
            ->allowEmpty('gstin');

        $validator
            ->scalar('status')
            ->allowEmpty('status');

        return $validator;
    }
    public function searchManager()
    {
        $searchManager = $this->behaviors()->Search->searchManager();
        $searchManager
            ->add('q', 'Search.Like', [
                'before' => true,
                'after' => true,
                'fieldMode' => 'OR',
                'comparison' => 'LIKE',
                'wildcardAny' => '*',
                'wildcardOne' => '?',
                'field' => ['code', 'description']
            ]);;

        return $searchManager;
    }

    public function buildRules(RulesChecker $rules)
    {
        $rules->add($rules->isUnique(['email']));
        $rules->add($rules->isUnique(['code']));

        return $rules;
    }
}

Please help me to resovle my issue

ADmad commented 6 years ago

This is an issues tracker not a help forum. For support please use one of CakePHP's official support channels.

robivin commented 4 years ago

@karthikeyanangler How did you fix this problem?