-1

I have a good functioning search tool at present using cakeDC search plugin. I can search very well with the pagination.

My problem here is that when i search from page:2 it doesn't at all.

here is my code:

Customer model

public $actsAs = array('Search.Searchable');
public $filterArgs = array(
    'searchTerm' => array(
        'type' => 'like',
        'field' => array('Customer.name', 'Customer.mobile', 'Customer.address'),
        'filter' => array('type' => 'query', 'method' => 'orConditions')
    )
);

public function orConditions($data = array()) {
    $filter = $data['filter'];
    $cond = array(
        'OR' => array(
            'Customer.name LIKE' => '%' . $filter . '%',
            'Customer.mobile LIKE' => '%' . $filter . '%',
            'Customer.address LIKE' => '%' . $filter . '%',
    ));
    return $cond;
}

CustomersController

 public $components = array('Paginator', 'Session', 'Search.Prg');

 public $presetVars = true;

 public function index() {
    $this->Prg->commonProcess();
    $this->paginate = array();
    $conditions = $this->Customer->parseCriteria($this->passedArgs);
    $this->Customer->recursive = 0;
    $this->paginate = array(
        'limit' => 5,
    );
    $this->set('customers', $this->paginate($this->modelClass, $conditions));
    $this->set('model', $this->modelClass);
}

index.ctp

<?php echo $this->Form->create() ?>
<?php echo $this->Form->input('searchTerm', array('class' => 'form-control','placeholder' => 'search for customer', 'label' => FALSE,'url' => array_merge(array('action' => 'index'), $this->params['pass']))); ?>
<?php echo $this->Form->end() ?>

Error: The requested address '/KPautos/products/index/page:2?searchTerm=j' was not found on this server.

Search is not working on page:2...

Any help would be heartily appritiated...Thank you in advance

  • Can you just show your code? How to search? – Sadikhasan Sep 25 '14 at 10:27
  • you do not have any page 2 for searchTerm 'j' you can redirect user back to search for such case – Abhishek Sep 25 '14 at 11:12
  • @Sadikhasan i have edited my question and provided the code for the search....actually i have used cakeDC search plugin. – Finsok Yagman Sep 26 '14 at 03:29
  • @Abhishek i have searchTerm'j' in page 2 – Finsok Yagman Sep 26 '14 at 03:31
  • @Abhishek the plugin is *nowhere* causing a 404. Nor by default CakePHP will bring a 404 but instead simply show an empty page when the page number is higher than the amount of available records. – floriank Sep 26 '14 at 10:44
  • i had same issue when i just changed page number manually to 20 instead of 2 where data was in my page, cakephp shows error if you do not have n pages of data while you are accessing to – Abhishek Sep 26 '14 at 11:05
  • just checked again Error: The requested address '/website/jobs/my_jobs/page:20' was not found on this server. while address '/website/jobs/my_jobs/page:2' works well and show content using 2.5.3 v of cakephp. – Abhishek Sep 26 '14 at 11:06

2 Answers2

1

Try to write this code for create form

<?php echo $this->Form->create(null, array('type'=>'get','url' => array('page'=>'1')));?>

Instead of

<?php echo $this->Form->create() ?>
Sadikhasan
  • 18,365
  • 21
  • 80
  • 122
0

i have the same problem when i search from any page in pagination with CakeDC plugin with CakePHP 2.6, I understand that page:2 or page:3 not exist, so thats the reason when do a search it marks Not Found, so thanks to Sadikhasan i changed the form create to:

echo $this->Form->create(null, array('novalidate' => true,'type'=>'get','url' => array('action'=>'index')));

Where index is the principal page that i use for search..