$userModel = User::model (); $userModel->count (); $userModel->count ($condition); $userModel->count ($condition, $params); $userModel->countbyattributes ($attributes); $userModel->countbyattributes ($attributes, $condition); $userModel->countbyattributes ($attributes, $condition, $params); $userModel->countbysql ($sql); $userModel->countbysql ($sql, $params); $userModel = User::model (); $userModel->find (); $userModel->find ($condition); $userModel->find ($condition, $params); $userModel->FINDBYPK ($PK); $userModel->findbypk ($PK, $condition); $userModel->findbypk ($PK, $condition, $params); $userModel->findbyattributes ($attributes); $userModel->findbyattributes ($attributes, $userModel); $userModel->findbyattributes ($attributes, $userModel, $params); $userModel->findbysql ($sql); $userModel->findbysql ($sql, $params); The return value is an array of objects, and NULL is returned if NULL. For a record $findResult = $userModel->find (' Islock =: Islock and phone_status=:p hone_status ', Array (': islock ' = 1, ' :p hone_status ' =>1)); Phone_status, Echo $findResult. <br/> "; Var_dump ($findResult->attributes); if ($userModel->find (' user_id=260 ')) {echo ' find '; }else{echo ' no find '; }
Explanation: A record is returned above assuming that you want to return more than one data FindAll class
$condition is the general SQL inside WHERE clause, a character channeling
$params is an array that assigns a value to a placeholder
Find out all the data:
$userinfo = $userModel->findallbyattributes (Array (' Islock ' =>1, ' phone_status ' = 0)); foreach ($userinfo as $k = + $v) { echo $v->user_id. $userinfo [$k][user_id]. " <br/> "; }
Visible. The result is a two-dimensional array.
Talk Cdbcriteria and model objects in combination
$criteria = new Cdbcriteria; if ($condition) $criteria->condition = $condition; $criteria->offset = $offset; if ($order) $criteria->order = $order; if ($limit! = "All") $criteria->limit = $limit; if (!empty ($more _criteria)) { $criteria->mergewith ($more _criteria); } $Model = new $modelName; if (!empty ($with _array)) { $result = $Model->with ($with _array)->findallbyattributes ($attributes, $ criteria); } else{ $result = $Model->findallbyattributes ($attributes, $criteria); }
YII database Query