Hi guys,
I would like to ask for guidance :) I just started using cakephp yesterday.
So I'm still on the learning process.
So yeah, I have this search action. It's working (at least it's what I
think). But when I press the search button, no matter what I input, the
action outputs all contents from the database even if I placed a condition.
Please refer to my code below.
Controller
public function search() {
$keyword = '%'.$this->params->query['keyword'].'%';
$cond=array('OR'=>array('Job.id LIKE' => $keyword,'Job.product LIKE' =>
$keyword) );
if($this->request->is('post')){
$list = $this->Job->find('all',array('conditions'=>$cond));
$this->set('results', $list);
}
}
View
<div id="search_box">
Search
<?php echo $this->Form->create('Job', array('url' => array('action' =>
'search'))); ?>
<?php echo $this->Form->input('keyword', array('style' => 'width: 250px;',
'label' => false)); ?>
<?php echo $this->Form->end('Search'); ?>
</div>
Id
Product
Actions
<?php foreach ($results as $job): ?>
<?php echo $this->Html->link($job['Job']['id'], array('action' =>
'view', $job['Job']['id'])); ?>
<?php echo $job['Job']['product']; ?>
<?php echo $this->Html->link('Edit', array('action' => 'edit',
$job['Job']['id'])); ?>
<?php echo $this->Form->postLink('Delete', array('action' => 'delete',
$job['Job']['id']), array('confirm'=>'Are you sure you want to delete this
post?')); ?>
<?php endforeach; ?>
<?php unset($job); ?>
--
View this message in context: http://cakephp.1045679.n5.nabble.com/Simple-search-working-but-not-in-an-intended-way-tp5716478.html
Sent from the CakePHP mailing list archive at Nabble.com.
--
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP
---
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cake-php+unsubscribe@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/groups/opt_out.
Saturday, September 14, 2013
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment