Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Google Sign In with OpenID

search filter

edited September 2013 in Apps

I need to create a search filter for a catalog generated by a custom app's handler. The best thing would be to have the filter in a block which can update the custom app's handler. Is there an example in Elefant I can follow to do that?

Comments

  • You mean you need one block to contain a filter (as in a select box or something similar) that will affect the main handler? All you should really need in the block is to generate a form like this:

    <form method="GET" action="/myapp/mainhandler">
        <select name="category">
            <option value="">- category -</option>
            <option value="1">One</option>
            <option value="2">Two</option>
        </select>
        <button>Go</button>
    </form>
    

    From there, your main handler would do something like this:

    <?php
    
    $query = myapp\MyModel::query ();
    
    if (isset ($_GET['category']) && ! empty ($_GET['category'])) {
        $query->where ('category', $_GET['category']);
    }
    
    $results = $query->fetch (10, 0);
    
    ?>
    
  • That was perfect for filters containing static data.

    Would it be possible, inside the block, to fetch the data from DB?

    Should I create a dynamic object to be inserted by editor?

  • That sounds like the right approach, yes.

Sign In or Register to comment.