Thursday, 15 September 2011

php - Yii relation with multiple rows -



php - Yii relation with multiple rows -

i have 3 tables i'm trying bring together using relation

my tables are

state store contacts ca|california 1|bestbuy|ca 1|1|phone|888888 2|1|phone|555555 3|1|phone|777777

in store model, have relations

public function relations() { homecoming array( '_state' => array(self::belongs_to, 'state', 'state'), '_contact' => array(self::many_many, 'contact', '', 'foreignkey' => array('id'=>'store_id')), ); }

how phone number id 1? or there improve way?

when phone call $model->_contact->phone; error

preg_match() expects parameter 2 string, array given

your relations seem fine, $model->_contact provides array of contact models. show phone numbers do:

foreach($model->_contact $contact) { echo $contact->phone; }

php yii

No comments:

Post a Comment