Have you tired calling the model's create() method before calling the
save() method? create() initializes the model for saving a new record
(http://api.cakephp.org/
class_model.html#2edb2497b980ad65e76ddda6d2494d97)
On May 3, 8:33 pm, ifcanduela <[EMAIL PROTECTED]> wrote:
> I'll follow your advice and paste the relevant code :)
>
> The Region model:
> ------------------------------------------------
>
> class Region extends AppModel
> {
> var $name = "Region";
>
> var $validate = array(
> 'name' => VALID_NOT_EMPTY
> );
>
> var $hasMany = array(
> 'Country' => array(
> 'className' => 'Country',
> 'foreignKey' => 'region_id'
> )
> );
>
> }
>
> The Country model:
> ------------------------------------------------
>
> class Country extends AppModel
> {
> var $name = "Country";
>
> var $validate = array(
> 'name' => VALID_NOT_EMPTY
> );
>
> var $belongsTo = array(
> 'Region' => array(
> 'className' => 'Region',
> 'conditions' => '',
> 'order' => '',
> 'foreignKey' => 'region_id'
> )
> );
>
> var $hasMany = array(
> 'Travel' => array(
> 'className' => 'Travel',
> 'foreignKey' => 'country_id'
> )
> );
>
> }
>
> The add() action in countries_controller:
> ------------------------------------------------
>
> function add($region_id = null)
> {
> if (!empty($this->data))
> {
> $this->data['Country']['region_id'] = $region_id;
> if ($this->Country->save($this->data))
> {
> $this->flash('New country added.', '/countries/index/' .
> $region_id, 2);
> }
> }
> else
> {
> $this->set('region_id', $region_id);
> }
>
> }
>
> And the add.thtml view:
> ------------------------------------------------
>
> <h1>New contry</h1>
>
> <form method="post" action="<?php echo $html->url('/countries/add/' .
> $region_id) ?>">
> <p><span class="redText">*</span>Country name:
> <?php echo $html->input('Country/name', array('size' =>
> '25')) ?>
> <?php echo $html->tagErrorMsg('Country/name', 'A name is
> mandatory.') ?>
> </p>
>
> <p>
> <?php echo $html->submit('Save'); ?>
> </p>
>
> <p>All fields marked <span class="redText">*</span> are mandatory.
> </p>
> </form>
>
> If thre's something missing, just tell me.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---