所以我有这样一个模型:Yii的:避免重复的表单对象从模型的所有属性
class MyClass
{
public $customer = null;
public $address = null;
}
而且形式是这样的:
class MyForm extends CFormModel
{
public $customer = null;
public $address = null;
/**
* Declares the validation rules.
*/
public function rules()
{
return array(
array('customer, address', 'required'),
array('verifyCode', 'captcha', 'allowEmpty'=>!CCaptcha::checkRequirements()),
);
/**
* Declares customized attribute labels.
* If not declared here, an attribute would have a label that is
* the same as its name with the first letter in upper case.
*/
public function attributeLabels()
{
return array(
'verifyCode'=>'Verification Code',
);
}
}
我想这样做,在我的表单中扩展模型,但是你不能在PHP中做多个对象继承。
我该如何做到这一点,以避免重复模型中的所有字段属性?
如果您正在考虑制定一个自定义窗体来检索值,各种型号,我建议你通过查看一些空白模型,然后检索他们每个人在提交时在控制器中。 – sucotronic
,如果我扩展了CActiveRecord,它就会工作,但由于我没有,我错过了我模型中的所有验证代码。任何想法如何处理? –
如果'MyClass'对象要存储在数据库中,正确的方式是扩展CActiveRecord,否则可以直接使用CFormModel对象。我不明白为什么你需要一个不同的类来保存两个属性。你能详细说明为什么你需要第一堂课,不能只用第二堂课吗? – sucotronic