Basically I Have a HATBM between "A" and "B" tables,
at the "A" controller, once the data for "A" has been entered I want
to save "A" and "A_B" tables .
I read the " How to add item using HABTM relation " disussion but
still cant get it done.
This is what i got so far:
// within "A" controller:
function add() {
if (!empty($this->data)) {
$BId=$this->Session->read('BId');
$this->A->create();
if ($this->A->save($this->data)) {
$lastCreated=$this->A->find('first',
array('conditions' => array('A.name' => $this->data['A']['name']),
'fields'=>'id'));
$this->set('Bid',$BId);
$this->set('Aid',$lastCreated['A']['id']);
}
// within "A" view
echo $this->Form->input('A_B.A_id', array('type'=>'hidden' , 'value'=>
$AId));
echo $this->Form->input('A_B.B_id', array('type'=>'hidden' , 'value'=>
$BId));
...
thanks
Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.
You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment