Friday, February 24, 2012

Re: My form is not saving any information

The Same issue i do have so please some body help...





On Fri, Feb 24, 2012 at 6:25 AM, reynierpm@gmail.com <reynierpm@gmail.com> wrote:
Hi every:
I have a table called Information with some relations 1:m with some others tables. The model for Information table is as follow:
<?php
App::uses('AppModel', 'Model');
class Information extends AppModel {
public $useTable = 'informations';
public $displayField = 'name';
public $validate = array(
'name' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'The field name can not be empty',
),
),
'lastname' => array(
'notempty' => array(
'rule' => array('notempty'),
'message' => 'The field lastname can not be empty',
),
),
'email' => array(
'email' => array(
'rule' => array('email'),
'message' => 'The email address is not correct',
),
),
);

public $belongsTo = array(
'Country' => array(
'className' => 'Country',
'foreignKey' => 'countries_id',
'conditions' => '',
'fields' => '',
'order' => ''
)
);
public $hasMany = array(
'Educations' => array(
'className' => 'Education',
'foreignKey' => 'candidate_id',
'dependent' => true
),
'Experiences' => array(
'className' => 'Experience',
'foreignKey' => 'candidate_id',
'dependent' => true
),
'Attachments' => array(
'className' => 'Attachment',
'foreignKey' => 'candidate_id',
'dependent' => true
)
);
}

Then in my controller InformationController I have this code for add a new information:
public function add() {
if ($this->request->is('post')) {
$this->Information->create();
if ($this->Information->save($this->request->data)) {
$this->Session->setFlash(__('The information has been saved'));
$this->redirect(array('action' => 'index'));
} else {
$this->Session->setFlash(__('The information could not be saved. Please, try again.'));
}
}
$countries = $this->Information->Country->find('list');
$this->set(compact('countries'));
}

But surprise the record is created but empty, why?

Ing. Reynier Pérez Mira

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
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

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
 
 
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

No comments: