I am rather new to CakePHP, but I may be able to help you.
Something like is what I would do:

search.thtml:
    <?php echo $html->input('Recipe/name'); ?>
    <div class="submit">
    <?php echo $html->submit('search');?>
    </div>

in controller:
    function search()
    {
        if(empty($this->data))
        {
            $this->render();
        }
        else
        {
            $conditions =array();
            $search_term = $this->data['Recipe']['name'];
            $conditions['Recipe']['name'] = "LIKE %{$search_term}%";
            $recipe_list = $this->Request->findAll($conditions);

            $this->set('recipe_list', $recipe_list);

            $this->render("index");
        }
    }

index.thtml:
    <?php if( !empty($recipe_list): ?>
      <table>
        <tr>
          <th>Action</th>
          <th>id</th>
          <th>name</th>
          <th>description</th>
        </tr>

        <!-- Here's where we loop through the list -->
        <?php foreach( $recipe_list as $recipe ): ?>
          <tr>
            <!-- // action -->
            <td>
              <?php echo $html->link('View',
                  "/recipes/view/".$recipe['Recipe']['id']); ?>
              <?php echo $html->link(
                  'Delete',
                  "/recipes/delete/{$recipe['Recipe']['id']}",
                  null,
                  'Are you sure?'
              ); ?>
              <?php echo $html->link('Edit',
                  "/recipes/edit/".$recipe['Recipe']['id']); ?>
            </td>
            <td><?php echo $recipe['Recipe']['id']; ?></td>
            <td><?php echo $recipe['Recipe']['name']; ?></td>
            <td><?php echo $recipe['Recipe']['description']; ?></td>
          </tr>
        <?php endforeach; ?>
      </table>
    <?php endif; ?>

First, it will render search view with form, then when submit button is
pressed, then construct $conditions with text search, then find all.
When you use $this-data directly for conditions, it will add empty
field if any, too, so it is important to make sure the $conditions
contains only the fields you want to search. Also, CakePHP supports
many format for conditions, such as string or array.
Set the list data for the view (or just assign to $this->data, if you
like), then render in another view, "index" in your case. index.thtml
loop through the list, and show the result.
If you want to reuse the same page, then you probably can just put and
render in the same view, too.

Hope this helps you.

Sohei


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to