Quote:
baloch wrote:
is critirea about setting like where clause, limit, orderby, groupy etc or something else?
Yes!
There are two classes in class/criteria.php:
Criteria() - Lets you create ONE condition for using in the "where" section of the query
CriteriaCompo() - Lets you use one or more Criteria and allows you to set limit, start, sortby and orderby for your query.
Both classes are available globaly after the inclusion of mainfile.php so you can use them without need to include files.
All you need is to do this:
$criteria = new Criteria('uid', 3);
//This will be translated in: where uid=3
$criteria = new Criteria('uid', 3, '>');
//This will be translated in: where uid>3
$criteria = new Criteria('uid', '(3, 5, 8)', 'IN');
//This will be translated in: where uid IN(3, 5, 8)
The best part is CriteriaCompo:
$criteria1 = new Criteria('uid', 3 '<>');
$criteria2 = new Criteria('post', 0, '>');
$criteria = new CriteriaCompo();
$criteria->add($criteria1);
$criteria->add($criteria2, 'OR');//'AND' is used by default
//this will result in : where (uid<>3 OR post>0)
//other options
$criteria->setSort('uname');
$criteria->setOrder('ASC');
$criteria->setLimit(10);
$criteria->setStart(0);
Criteria and Handlers are good friends:
$myObjects = $myhandler->getObjects($criteria);
Don't forget that Criteria does not have add() and setLimit() etc. Criteria is just for a single condition. If you need more power allways use CriteriaCompo().
You can pass a Criteria directly to CriteriaCompo like this:
$criteria = new CriteriaCompo(new Criteria('uid', 3 '<>'));
$criteria->setLimit(10);
$myObjects = $myhandler->getObjects($criteria);
Hope you found it easy to understand!