On Apr 7, 9:07 pm, Kyle Decot <[EMAIL PROTECTED]> wrote:
> I am creating a skatepark directory website, and I want to include a
> filter/search box where you can search parks by name, and filter by
> state, price, size, etc. Has anybody done anything similar, or have
> any suggestions on how to do this? Thanks for the help. '
>
> My website is:http://www.theskateparkdirectory.com/browse/

1. Bake "foos" for Controller, Model and Views

2. /views/foos/index.ctp

<?php
//search form
echo $form->create('Foos', array(
    'action' => 'index',
    'method' => 'get' // Important
));
echo $form->input('q', array(
    'label' => false
));
echo $form->submit('Search');
echo $form->end();

//Important, before paginate elements
$paginator->options(array(
    'url' => $this->params['named']
));
?>


3. /app/app_controller.php
<?php
class AppController extends Controller
{
    //helper method to redirect query to named
    // http://foo.com/foos/index/?q=x&blah=y to
    // http://foo.com/foos/index/q:x/blah:y
    function _redirectQueryToNamed($whitelist_param_names = null)
    {
        $query_strings = array();
        if (is_array($whitelist_param_names)) {
            foreach($whitelist_param_names as $param_name) {
                if (!empty($this->params['url'][$param_name])) { //
query string
                    $query_strings[$param_name] = $this->params['url']
[$param_name];
                }
            }
        } else {
            $query_strings = $this->params['url'];
            unset($query_strings['url']['url']); // Crazy, Remember:
Can't use ?url=foo
        }
        if (!empty($query_strings)) {
            $query_strings = am($this->params['named'],
$query_strings);
            $this->redirect($query_strings, null, true);
        }
    }
}
?>


4. /app/controlers/foos_controller.php

<?php
class FoosController extends AppController
{
    function index()
    {
        $this->_redirectQueryToNamed();
        // <The rest of the baked paginate codes>
        // stuff $this->params['named'] in conditions
    }
}
?>

Summary: Have the form in GET and force the page to namedArg; then
retain the namedArgs in paging. Then, use $this->params['named'] in
paginate conditions.

--
  <?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com    Blog: http://rajeshanbiah.blogspot.com/
--~--~---------~--~----~------------~-------~--~----~
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?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to