yii数据表关联操作

首先在model中进行表关联

	public function relations() {
		return array_merge(parent::relations(), array(
			'OrderAddonGiftinstock' => array (self::HAS_ONE, 'OrderAddonGiftinstock', 'order_id' ),
		));
	}


在增加和修改的页面用下面的代码来表示

<td width=100>
										<div class="bh-text bh-show_inline">
 											<?php echo $form->textField($model->s('Addon'),'telephone', array(
 												'name' => HActiveForm::name($model, '[Addon]', 'telephone'),
 												'pattern'=>'(0(10|2[0-5789]|\\d{3})-?\\d{7,8})?',
 												'error'=>'错误的电话号'
 											)); ?>
                                        </div>
									</td>


在查看页面读取数据为

<?php echo $model->OrderAddonGiftinstock->telephone;?>




Meet so Meet. C plusplus I-PLUS....
原文地址:https://www.cnblogs.com/iplus/p/4489998.html