1

I'm making a form to search my application for users with their name or email. Specifically, I am trying to make a search engine, but I don't know how to send two parameters from my form to my controller in cakephp3.

// In my controller

       $keyword =$this->request->query('keyword' );
     $users = $this->Users->findAllByFirst_nameOrEmail($keyword);

// In my form

        <?= $this->Form->create("",['type'=>'get']) ?>
           <?=  $this->Form->control('keyword'); ?>
           <button>Search</button>
        <?= $this->Form->end() ?>
Mickey
  • 570
  • 3
  • 11
  • Please post your questions in English only. – Qirel Aug 09 '19 at 14:43
  • I am making a form to search my application for users with their name or email, that is, I am trying to make a search engine, but I don't know how to send two parameters from my form to my controller in cakephp3. – Cristian Quevedo Aug 09 '19 at 14:47
  • What's not working about your existing code? It looks like it should be fine, as far as it goes. – Greg Schmidt Aug 09 '19 at 18:02

1 Answers1

1

You just need to add another argument in your method, here you are using findAllByFirst_nameOrEmail, Here you have two fields so you have to give two arguments. In your case you just can change your code

$users = $this->Users->findAllByFirst_nameOrEmail($keyword);

to

$query   = $this->Users->findAllByFirstNameOrEmail($keyword,$keyword);

Check doc OR condition again Dynamic Finders

Alimon Karim
  • 4,354
  • 10
  • 43
  • 68