I have this as a basic starting point. Which does the basic search of the 2
fields title and description.
If I search for 1 word it works. If I use some, word, other it returns
nothing.
How can I search other tables for related data (TAGS)
CONTROLLER:
function search()
{
if (!empty($this->data)) {
$searchstr = $this->data['Post']['search'];
$this->set('searchstring', $this->data['Post']['search']);
$conditions = array(
'conditions' => array(
'or' => array(
"Post.title LIKE" => "%$searchstr%",
"Post.description LIKE" => "%$searchstr%"
)
)
);
$this->set('posts', $this->Post->find('all', $conditions));
}
}
VIEW:
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php echo
$html->link($post['Post']['title'],'/posts/view/'.$post['Post']['id']);?>
</td>
<td><?php echo $post['Post']['created']; ?></td>
</tr>
<?php endforeach; ?>
SEARCH FORM on what ever page you want to search from:
<?php
echo $form->create('Post',array('action' => 'search'));
echo $form->input('Post.search');
echo $form->end('Submit');
?>
-----Original Message-----
From: Mike Cook [mailto:[email protected]]
Sent: March-13-09 4:02 PM
To: CakePHP
Subject: Re: Search Function
Hi Dave,
I've just started looking into this myself. You could try these links;
http://www.assembla.com/wiki/show/searchable_behavior
http://thechaw.com/cakebook/source/plugins/searchable
http://bakery.cakephp.org/articles/view/search-feature-to-cakephp-blog-examp
le
http://bakery.cakephp.org/articles/view/integrating-zend-framework-lucene-wi
th-your-cake-application
Hope this helps.
On Mar 13, 7:15 pm, "Dave Maharaj :: WidePixels.com"
<[email protected]> wrote:
> Does anyone know a starting place to read up on creating a search
function?
>
> I want to put the search on my POSTS controller where the search will
> look thru not only the POSTS but related HABTM tables. So for example
> if the POST article has a TAG "Beauty" and the person searching types
> in Beauty even though beauty may not have been typed into the actual
> article it will still find the article based on the TAG as well.
>
> Dave
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---