Model::where
Set Where Parameter
Description
public self Model::where( string $query, [ array $data = [], string $andOr = 'AND' ] )
Arguments
Name | Data type | Default | Remarks |
---|---|---|---|
$query | string | Where query string | |
$data | array | [] | Where query parameter |
$andOr | string | 'AND' | Condition chain from the previous query AND or OR |
Example
Controller
$model = new Model(false, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));
$model->where('news_id = ?', array(1));
// Get filtered records
// SELECT * FROM cms_news WHERE news_id = 1
$records = $model->find();
Complex WHERE query
Controller
$model = new Model(false, array(
'table' => 'cms_news',
'id' => 'news_id',
'visible' => 'visible',
));
$model->where('news_id = ?', array(1));
$model->whereOpen();
$model->where('title = ?', array('foo'));
$model->where('created_at <= ?', array('2021-01-01'), 'OR');
$model->whereClose();
// SELECT *
// FROM cms_news
// WHERE
// news_id = 1
// AND (
// title = 'foo'
// OR created_at <= '2021-01-01'
// )
$records = $model->find();