Load Posts With First Letter


How I can return posts with first letter of title, In Sql we can use below code:


FROM posts

WHERE title LIKE ‘%B’

LIMIT 0 , 30

How in Yii ?!

Assume you already have Posts model,

then it should be Posts::model->findAll(“title LIKE ‘B%’”);

Or if you like, you can use dbcommand. See link:


$posts = Yii::app()->db->createCommand()


->where("title LIKE 'B%'")


Thank you my friend, It’s Good.


For standard characters it’s OK, How I can request posts with Persian characters (UTF8), This code not work:

Posts::model->findAll(“title LIKE ‘ب%’”);

  • ب is B in persian alphabet. *


Try this:

Posts::model->findAll("title LIKE :q", array(':q' => 'ب%'));

PS. wow, you have built-in emoticons in your alphabet. How cool is that?

Thank you, It’s Worked.

Yes ! In some alphabets we can use characters as a emoticons !

You can see HERE about Persian standard alphabet .

Yeah, arabic script is beautiful, looks like ornament or something.

I should definitely learn it.

Persian language is beautiful too, It’s Very nice language.

Content AND design in one entity.