2 responses to “SQL Conditions – A CakePHP Component Class”

  1. grggnn

    hello and thanks for making such a useful component. i’m kind of n00b to cakePHP so naturally i’m running into some problems. essentially, i’m trying to search through a list of records by date. ideally, the user would specify a date and the app would search the table for all records whose ‘start_date’ field was < the date specified. so if the search criteria was Jan 1, 2008 – it would pull up everything before that date.

    here's my setup:

    table name: jobs
    search field name: start_date

    default.ctp

    create('Job', array('action' => 'index', 'class' => 'advanced_search'));
    echo $form->input('search_sdt', array('default' => @$this->params['named']['search_sdt'],'div' => false, 'type' => 'date'));
    echo $form->submit('Go!', array('div' => false,));
    echo $form->end();

    echo $form->create('Job', array('action' => 'index', 'class' => 'advanced_search'));
    echo $form->input('clear_conditions', array('type' => 'hidden', 'value' => 1, 'div' => false,));
    echo $form->submit('Reset', array('div' => false,));
    echo $form->end();
    ?>

    jobs_controller.php

    var $components = array(
    'SqlConditions' => array(
    'conditions' => 'criteria_conditions',
    'admin_conditions' => 'admin_criteria_conditions',
    'active_actions' => array('index', 'admin_index'),
    ),
    );

    // For use with SqlConditions component.
    // Regular Site Search Conditions
    var $criteria_conditions = array(
    array('name' => 'search_sdt', 'fields' => 'Job.start_date', 'type' => 'date', 'condition' => ' 'admin_search_sdt', 'fields' => 'Job.start_date', 'type' => 'date', 'condition' => 'SqlConditions->build();
    $this->Job->recursive = 0;
    $this->set('jobs', $this->paginate($sql_conditions));
    }

    i’ve also copied sql_conditions.php into controllers/components.
    any help and/or light you can shed on this would be super appreciated.

    thanks!

Leave a Reply

You must be logged in to post a comment.