hd.
hd.

Reputation: 18306

return a row of a table using Active Record in Yii

I want to return a field of a row of table which has id = 4 in a model for example Post.

Which one should I use find() method or findByAttributes() ? And what is the correct syntax for it ?

Upvotes: 0

Views: 252

Answers (1)

Stu
Stu

Reputation: 4150

To grab a model by its primary key I'd suggest `findByPk(). It's one of the most simple methods to use;

$id = 4;
$model = Post::model()->findByPk($id);

For other method syntaxes, have a read through the Yii Active Record wiki and Yii Active Record documentation, they're really helpful when starting out.

Upvotes: 1

Related Questions