php - 'if' statements in model to format SQL query filter -
php - 'if' statements in model to format SQL query filter -
i not sure keywords utilize search answer, simple nil found.
model used sql queries far know. no logic.
so filters?
for illustration
function getitems($partneruserid) { $param = ""; $params = array(); if ($partneruserid !== '') { $param = "and z.x = ?"; $params[] = $partneruserid; } $sql = "select ... z z.a = 1 $param"; homecoming db::connection($connection)->select($sql, $params); }
and in real world illustration there much more statements. how model should or should logic in controller , pass filter strings parameters model function?
this basic layered architecture , construction of query should done in info mapper or dao classes. if redundant code or complex code, can create util static method , phone call info mapper layer.
php if-statement
Comments
Post a Comment