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

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -