I am looking for some help in understanding how to use the array/closure type
of configuration that is used in zf2 to manage the construction of simple
where queries in a mapper. It's much easier to explain with an example:

/    protected function buildQuery(\Zend\Db\Sql\Select $select, $params){
        $formFields = array(
            'name' => function(\Zend\Db\Sql\Select $select, $value){
                $where = new \Zend\Db\Sql\Where();
                $where->like('forename', '%' . $value . '%');
            },
            'dateRegistered' => function(\Zend\Db\Sql\Select $select,
$value){
                $where = new \Zend\Db\Sql\Where();
                $where->between('date_registered', $value['from'],
$value['to']);                
            }
        );
        
        foreach($params as $key => $val){
            if(array_key_exists($key, $formFields)){
                //? construct where object
            }
        }

    }/

so for each form in the field i can quickly build the where clause without
too much hassle. The question i have is how to actually use the above config
array - as in, how do i pass in a select or where object to be populated?

So the following array
/
        $params = array('name' => 'John',
                        'dateRegistered' => array(
                            'from' => '01/01/2013',
                            'to' => '01/02/2013')
        );
/
...would produce the following where clause
/where forename like '%John%' and date_registered between '01/01/2013' and
'01/02/2013'/



--
View this message in context: 
http://zend-framework-community.634137.n4.nabble.com/using-config-array-with-closure-to-build-where-clauses-tp4660536.html
Sent from the Zend Framework mailing list archive at Nabble.com.

-- 
List: [email protected]
Info: http://framework.zend.com/archives
Unsubscribe: [email protected]


Reply via email to