20.11.2014 Views

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

O Guia Definitivo do Yii 1.1

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

also use the following code to escape the special characters to prevent them from being<br />

treated as wildcards:<br />

$keyword=$_GET['q'];<br />

// escape % and _ characters<br />

$keyword=strtr($keyword, array('%'=>'\%', '_'=>'\_'));<br />

$command->where(array('like', 'title', '%'.$keyword.'%'));<br />

order<br />

function order($columns)<br />

The order method specifies the ORDER BY part of a query. The $columns parameter<br />

specifies the columns to be ordered by, which can be either a string representing commaseparated<br />

columns and order directions (ASC or DESC), or an array of columns and order<br />

directions. Column names can contain table prefixes. The method will automatically quote<br />

the column names unless a column contains some parenthesis (which means the column<br />

is given as a DB expression).<br />

Below are some examples:<br />

// ORDER BY `name`, `id` DESC<br />

order('name, id desc')<br />

// ORDER BY `tbl_profile`.`name`, `id` DESC<br />

order(array('tbl_profile.name', 'id desc')<br />

limit and offset<br />

function limit($limit, $offset=null)<br />

function offset($offset)<br />

The limit and offset methods specify the LIMIT and OFFSET part of a query. Note that<br />

some DBMS may not support LIMIT and OFFSET syntax. In this case, the Query Builder<br />

will rewrite the whole SQL statement to simulate the function of limit and offset.<br />

Below are some examples:<br />

// LIMIT 10<br />

limit(10)<br />

// LIMIT 10 OFFSET 20<br />

limit(10, 20)<br />

// OFFSET 20<br />

offset(20)

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!