Thursday, April 29, 2010

Displyaing two models data in a view

Hi, I'm designing travel document application. Here's the process:
A person submits his/her data. Applicant data will be saved in applicants
table.
For those whose data is already approved, the data will be saved in
approved_applicants table.
After saving applicant data to approved_applicants table, we assign him/her
a travel document by inserting a record in documents table with newly
created approved applicant id as foreign key
here are the related tables:
CREATE TABLE `applicants` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`pob` varchar(25) DEFAULT NULL,
`dob` date NOT NULL,
`file_num` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
)

CREATE TABLE `documents` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`document_number` varchar(10) NOT NULL,
`approved_applicant_id` int(10) DEFAULT NULL,
`status` varchar(15) DEFAULT NULL,
`app_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE
CURRENT_TIMESTAMP,
`created` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
PRIMARY KEY (`id`)
)

CREATE TABLE `approved_applicants` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
`name` varchar(30) NOT NULL,
`pob` varchar(25) DEFAULT NULL,
`dob` date NOT NULL,
`file_num` varchar(10) NOT NULL,
PRIMARY KEY (`id`)
)

So what I want to ask is how I can display applicant data and travel
document in one page ?
If we submit this form. the applicant data will be saved to
approved_applicants table and a record in documents table will be inserted.

What I've already done is I put this code in ApprovedApplicant controller
function result() {

if(!empty($this->data)) {
//is this the right way to pass document data to the view ?
$docs =
$this->Document->find('first',array('conditions'=>array('Document.document_type_id'=>1,'status'=>'new'),
'fields'=>array('MIN(document_number) as max_doc')));

$this->set('docs',$docs);
$this->data =
$this->Applicant->find('first',array('conditions'=>array('Applicant.reg_num'=>
$this->data['Applicant']['reg_num'])));
} else {
$this->redirect(array('controller'=>'applicants','action'=>'search'));
}
}

function process() {
if(array_key_exists('confirm',$this->params['form'])) {
//save applicant data to approved applicants table
//insert new record in documents table with newly created approved
applicant id as foreign key
}
} else {

}
}

result.ctp
<?

echo $form->create('Applicant', array('action'=>'process'));
echo $form->input('name');
echo $form->input('pob');
echo $form->input('dob');
echo $form->input('address');
echo $form->submit('confirm', array('name'=>'confirm', 'div'=>false));
echo $form->submit('cancel', array('name'=>'cancel', 'div'=>false));

echo $form->end();

//document output should be here ??
?>
Any help will be greatly appreaciated
I use cake 1.2
Thanks
--
View this message in context: http://old.nabble.com/Displyaing-two-models-data-in-a-view-tp28408236p28408236.html
Sent from the CakePHP mailing list archive at Nabble.com.

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

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate