return a row of a table using Active Record in Yii

邮差的信 提交于 2019-12-11 18:48:01

问题


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 ?


回答1:


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.



来源:https://stackoverflow.com/questions/13993785/return-a-row-of-a-table-using-active-record-in-yii

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!