hello,
i have 2 model (activerecord), customer.php & address.php.
and than i want to create record use activerecord.
here my code:
private function saveCustomer($model){
// save customer
$cust = new Customer();
try{
// save customer address
$add = new Address();
$add->company = $model->company;
$add->firstname = $model->firstname;
$add->lastname = $model->lastname;
i get error:
Property "Address.company" is not defined.
and this address model
<?php
/**
* This is the model class for table "Address".
*
* The followings are the available columns in table 'Address':
* @property integer $address_id
* @property integer $customer_id
* @property string $company
* @property string $firstname
* @property string $lastname
* @property string $address_1
* @property string $address_2
* @property string $postcode
* @property string $city
* @property integer $country_id
* @property integer $zone_id
*/
class Address extends CActiveRecord
{
/**
* Returns the static model of the specified AR class.
* @return Address the static model class
*/
public static function model($className=__CLASS__)
{
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName()
{
return 'Address';
}
/**
* @return array validation rules for model attributes.
*/
public function rules()
{
// NOTE: you should only define rules for those attributes that
// will receive user inputs.
return array(
array('customer_id', 'required'),
array('customer_id, country_id, zone_id', 'numerical', 'integerOnly'=>true),
array('company, firstname, lastname', 'length', 'max'=>32),
array('address_1, address_2, city', 'length', 'max'=>128),
array('postcode', 'length', 'max'=>10),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('address_id, customer_id, company, firstname, lastname, address_1, address_2, postcode, city, country_id, zone_id', 'safe', 'on'=>'search'),
);
}
/**
* @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(
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels()
{
return array(
'address_id' => 'Address',
'customer_id' => 'Customer',
'company' => 'Company',
'firstname' => 'Firstname',
'lastname' => 'Lastname',
'address_1' => 'Address 1',
'address_2' => 'Address 2',
'postcode' => 'Postcode',
'city' => 'City',
'country_id' => 'Country',
'zone_id' => 'Zone',
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
$criteria=new CDbCriteria;
$criteria->compare('address_id',$this->address_id);
$criteria->compare('customer_id',$this->customer_id);
$criteria->compare('company',$this->company,true);
$criteria->compare('firstname',$this->firstname,true);
$criteria->compare('lastname',$this->lastname,true);
$criteria->compare('address_1',$this->address_1,true);
$criteria->compare('address_2',$this->address_2,true);
$criteria->compare('postcode',$this->postcode,true);
$criteria->compare('city',$this->city,true);
$criteria->compare('country_id',$this->country_id);
$criteria->compare('zone_id',$this->zone_id);
return new CActiveDataProvider(get_class($this), array(
'criteria'=>$criteria,
));
}
}
thanks