Rather than walk through your code correcting it, I can give some hints and 
point you at the guide - because the answers are all there and it is the best 
way of learning.

1) You need to link your models appropriately: 
http://book.cakephp.org/view/1039/Associations-Linking-Models-Together
2) When you have done that, you can build an array in your controller that 
contains all of the data you need by doing the right find: 
http://book.cakephp.org/view/1017/Retrieving-Your-Data. Also look at the 
Containable behaviour because it will help you build the right find: 
http://book.cakephp.org/view/1323/Containable
3) When you do this, your array will have elements for each model
4) When you create the view, name the form inputs with the matching model name 
and field name (e.g. $this->Form->input('Model.field_name');
5) When the form data is submitted you'll see that $this->data is a structured 
array with elements named after your models.
6) Save the data using the correct save method; saveAll if the array is 
structured correctly or by looping through your $this->data and using save as 
many times as you need: http://book.cakephp.org/view/1031/Saving-Your-Data. Pay 
attention to the array format expected by each different save method because 
they are not all the same.

Jeremy Burns
[email protected]


On 30 Apr 2010, at 04:37, aveev wrote:

> 
> 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 [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

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 [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

Reply via email to