Skip to main content

Model::where

Set Where Parameter

Description

public self Model::where( string $query, [ array $data = [], string $andOr = 'AND' ] )

Arguments

NameData typeDefaultRemarks
$querystringWhere query string
$dataarray[]Where query parameter
$andOrstring'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();