to create a master detail you create your models for example
Models/master.php
<?php
class Master extends AppModel
{
var $hasMany = array('Detail'=>array(
'className'=>'Detail',
'foreignKey'=>'id_master')
);
}
?>
-------------------------------
Models/detail.php
<?php
class detail extends AppModel{
var $belongsTo = array('Master'=>array(
'className'=>'Master',
'foreignKey'=>'id_master')
);
}
?>
<?php
/**masters_controller.php*/
class MastersController extends AppController
{
var $uses = array('Master','Detail');
function add(){
if(!empty($this->data)) {
//Transaction
$this->Master->begin();
$save = true;
if(! $this->Master->save($this->data['Master']) ){
$save = false;
}
//Detail
foreach($this->data['Detail'] as $v) {
$this->Detail->id = null;
if( $this->Detail->save($v) ) {
$save = false;
}
}
if($save) {
$this->Master->commit();
$this->redirect('some place');
}else{
$this->Master->rollback();
}
}
}
}
?>
-----------------------------------------------------------
The view add for the Master controller
views/masters/add.thtml
<form method="post" action="add/">
<?php
//Master
echo $html->input('Master/name');
?>
<?php
//Detail
$i = 0;
echo $html->input("Detail][$i/quantity").'<br/>';
$i++;
echo $html->input("Detail][$i/quantity").'<br/>';
$i++;
echo $html->input("Detail][$i/quantity").'<br/>';
echo $html->submit('Save');
?>
</form>
------------------------------------
------------------------------------
------------------------------------
I hope there aren't many errors The most important thing is the
Idea :).
You can use javascript to add more items in to the detail
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---