Hi,

Maybe not an answer to your question but speaking from experiance and in no way 
to patronise but do what you know you can do now and enhance later. Dont get 
caught up trying to do things "the right way" because there is no such thing. 
And it will speed you up.

In my opinion, appyling this idealism to your question would mean writing a 
simple function that returns a sql query string from the params you stated. A 
point to stress here though is that you should make the function/method 
independant, allowing you to easily swap it out in the future, to how you would 
really like it implemented.

I feel doing things this way gives you a better understanding of your app and 
also a deeper understanding in app architecture as a whole.

Like I said at the start, my reply may not answer your question but it may make 
you reflect on it.

Daniel


tonystamp <[email protected]> wrote:

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