这个是模型的关系
/**
* @return array relational rules.
*/
public function relations()
{
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'category' => array(self::BELONGS_TO, 'Category', 'category_id'),
'author' => array(self::BELONGS_TO, 'User', 'author_id'),
'article_data' => array(self::HAS_ONE, 'ArticleData', 'article_id'),
);
}
这个是表单
<?php $form=$this->beginWidget('bootstrap.widgets.TbActiveForm',array(
'id'=>'article-form',
'enableAjaxValidation'=>false,
)); ?>
<p class="help-block">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<?php echo $form->textFieldRow($model,'title',array('class'=>'span5','maxlength'=>400)); ?>
<?php echo $form->textAreaRow($model,'description',array('rows'=>3, 'cols'=>50, 'class'=>'span8')); ?>
[u][b]//下面这行的问题.为什么不能这样用呢?有没有更好的方法?[/b][/u]
<?php echo $form->textAreaRow($model->article_data,'content',array('rows'=>6, 'cols'=>50, 'class'=>'span8')); ?>
<?php echo $form->textFieldRow($model,'tags',array('class'=>'span5','maxlength'=>120)); ?>
<?php echo $form->DropDownListRow($model,'category_id',CHtml::listData(Category::model()->findAll(),'id','name'),array('empty'=>'分类选择','class'=>'span5')); ?>
<?php echo $form->DropDownListRow($model,'status',$model->getStatus(),array('class'=>'span5')); ?>
<div class="form-actions">
<?php $this->widget('bootstrap.widgets.TbButton', array(
'buttonType'=>'submit',
'type'=>'primary',
'label'=>$model->isNewRecord ? 'Create' : 'Save',
)); ?>
</div>
<?php $this->endWidget(); ?>