# Passing variables to where clause

**URL:** <https://discourse.cakephp.org/t/passing-variables-to-where-clause/799>\
**Category:** Need Help\
**Created:** [July 25, 2016, 4:07am UTC](https://discourse.cakephp.org/t/passing-variables-to-where-clause/799 "2016-07-25T04:07:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![AshlessPhoenix](https://avatars.discourse-cdn.com/v4/letter/a/47e85d/32.png) [@AshlessPhoenix](https://discourse.cakephp.org/u/AshlessPhoenix)\
**Post date:** [July 25, 2016, 4:07am UTC](https://discourse.cakephp.org/t/passing-variables-to-where-clause/799/1 "2016-07-25T04:07:30Z")

</div>

in the documentation [here](http://book.cakephp.org/3.0/en/appendices/orm-migration.html) , I could find an example of passing variable to a query. That portion refers to model.

```php
 public function findFavorites(Query $query, array $options)
    {
        $for = $options['for'];
        return $query->matching('Users.Favorites', function ($q) use ($for) {
            return $q->where(['Favorites.user_id' => $for]);
        });
    }

```

Passing variables is handy in controllers who receives Request and then make a query that uses variables coming from the Request. It seems like contain, matching ( and perhaps andWhere and orWhere) can make use of this function ($q) use ($myVariable)… form, but that where cannot use it.  
I do need to write a where clause using $startDate and $endDate variables …  
I am new to Cakephp, this actually my first post on the forum. Thanks for any help
