2014-03-25 25 views
0

模式情况下,我们有两个型号Yii中,有几个以某种形式

class Base extends AbstractModel 
{ 
    public $id; 
    public $name; 

    public function tableName() 
    { 
     return 'table_base'; 
    } 
} 

class ExtendBase extends AbstractModel 
{ 
    public $id; 
    public $baseID; 

    public function tableName() 
    { 
     return 'table_base_extend'; 
    } 
} 

我就不一一介绍了所有,只是描述了主要的事情。

所以,现在我想要创建将结合这种形式的表单。并希望在行动做这样的事

public function actionSome() 
{ 
    $oBase = new Base(); 
    $aExtendBase = array(); // important this is array 

    for ($i = 1; $i <= 3; $i++) { 
     $aExtendBase[] = new Extend(); // fill in array, pre-create for form 
    } 

    if ($this->isPost()) { // protected custom method 
     if (isset($_POST['Base'], $_POST['ExtendBase'])) // here should be specific checker because we have several ExtendBase instances in form 
     { 
      // save Base model 
      // save each ExtendBase model 
     } 
    } 

    $this->render('formView', array('oBase' => $oBase, 'aExtendBase' => $aExtendBaes)) 
} 

所以问题是

  1. 如何创建视图等“组合拳”的形式;
  2. 如何在POST操作后获取所有表单数据(我的意思是每个数据);

回答

0

的解决方案,您可以创建一个模型(CFormModel),这并不代表ActiveRecord只是一个单一的形式。

我认为这将是您继续进行的最佳方式(假设我已正确理解您的问题)。

如果我是你,我会创建一个模型来表示这种形式只有规则(就像我说的CFormModel一个实例,而不是ActiveRecord),然后在你的控制,采取得到提交的元素和手动创建和/或更新这两个类的对象。