# Yii find ## find() - find ``` TableName::model()->find(); ``` - find with condition and params ```php TableName::model()->find(mixed condition, array params); Order::model()->find('orderId=:orderId', [':orderId' => 123456]); ``` - find with 關聯order 及 country 表 抓取 user 資料 ```php User::model()->with('order', 'country')->find(array( 'select' => 'id, name', 'conditoin' => 'id=:id', 'params' => array( ':id' => 1 ) )); ``` --- ## findAll() - findAll ``` TableName::model()->findAll(); example: Order::model()->findAll('status=1'); ``` - findAll with condition and params ```php User::model()->findAll([ 'select' => 'id, name', 'condition' => 'id=:id', 'params' => [ ':id' => '123456' ] ]); ``` - findAll with order ```php User::model()->findAll([ 'select' => 'id, name', 'order'=>'username' ]); ``` --- ## findByAttribute() - findByAttribute ```php /** array attribute mixed condition array params */ User::model()->findByAttribute( array('userid' => 1), $condition = 'username=:username and status=:status', $params = [ ':username' => 'john', ':status' => 1 ] ); ``` --- ## findByPk() - find data with primary Key ```php User::model()->findByPk(1); // get user id with 1 data ``` --- ###### tags: `Yii` `framework` `find` `PHP` `model`