I’m using the Friends of Cake Search plugin in my project, and it’s working great. I would, however, like the default view of my search page to be nothing but the search input form until the submit button is pressed. The default right now is to load everything and then filter based on the search criteria. Here’s the code for my search engine:
public function search()
{
$query = $this->MissionLessons->find('search', [
'search' => $this->request->getQueryParams()]
)
->contain(['Missions', 'ReqStatuses', 'Discrepancies', 'Engineers', 'Initiator']);
$this->paginate = [
'contain' => ['Missions', 'ReqStatuses', 'Discrepancies', 'Engineers', 'Initiator'],
];
$this->set('missionLessons', $this->paginate($query));
$this->set($this->getLists());
}
I thought that wrapping the whole thing in if ($this->request->is('post')
would do it, but then that caused problems in my search view, which is expecting the value of $missionLessons
to be set. Adding if (isset($missionLessons))
didn’t help. Here’s the relevant code for the results view, without the form:
<tbody>
<?php foreach ($missionLessons as $missionLesson): ?>
<tr>
<td class ="actions"><?= $this->Html->link(__($missionLesson->mission->mission_id), ['action' => 'view', $missionLesson->id]) ?></td>
<td><?= h($missionLesson->req_status->status) ?></td>
<td><?= $missionLesson->int_ext === 1 ? 'Internal' : 'External' ?></td>
<td><?= h($missionLesson->owner) ?></td>
<td><?= h($missionLesson->discrepancy->description) ?></td>
<td><?= h($missionLesson->engineer->full_name) ?></td>
<td><?= h($missionLesson->initiator->full_name) ?></td>
</tr>
<tr>
<td colspan="7"><?= "Description: " . $missionLesson->description ?></td>
</tr>
<?php endforeach; ?>
</tbody>
Any ideas on how I can keep the values of $missionLessons
hidden until after the user chooses some search criteria?