Hi, again… well, I finally developing my applications with Yii (it’s rocks )
Well, my probles may be is simple, but it's making me crazy.
I have two db tables Client and Address (in MySQL)
I need to take them separated because other tables are related with address too (eg. Bank)
Well
Client
client_id
client_name
client_lastname
client_id_address
Address
address_id
address_street
address_number
Both models are already maked.
My Client Model has the following relation
public function relations()
{
return array(
'adress'=>array(self::BELONGS_TO,'Address','client_id_address'),
);
}
I have no problem to see the related data on mi client/list (I modifiy that wiew to take address data too)
But my problem is that I want to collect all the data for a client among with his/her address in a single form.
Lets say
Name: (textfield)
Last Name: (textfield)
Street: (textfield)
Number: (textfield)
[SAVE]
I already modify mi ClientController in the following way:
public function actionCreate()
{
$c=new Client;
$c->adress = new Address; // I made the getter and setter for address adding a private member ($_address) to Client and making the correspondients methods.
if(isset($_POST['Client']))
{
//$c->attributes=$_POST['Client'];
$c->client_name = $_POST['client_name'];
$c->client_lastname = $_POST['client_lastna,e'];
$c->adress->address_street = $_POST['address_street'];
$c->adress->address_number = $_POST['address_number'];
if ($a->address->save()) {
$a->client_id_address = $a->address->getPrimaryKey();
if($a->save())
$this->redirect(array('show','id'=>$a->client_id));
}
}
$this->render('create',array('client'=>$a));
}
The problem is that when I submit the form, nothing is stored in my db, and I back to the form with the field street marked with css as a required field (but no error)
PLEASE!!! Anybody can help me to solve this problem?