I've been working on this over the last 10 days and still haven't
found a solution. I haven't even found any clues. It's impossible to
tell how many people have read this but not one person has replied so
I'm bumping it up the list.

On Jun 1, 4:00 pm, Stuart <[email protected]> wrote:
> I haven't experienced this before but I'll try to explain it. I have a
> Facilities model that hasMany Documents and Document belongsTo
> Facility. When a user creates a new facility they have the option of
> uploading a document related to that facility. If a document is
> uploaded when the facility is created all is well. The problem is when
> a user chooses to add a document and associate it with an existing
> facility. When the document is uploaded all table columns are
> populated as expected except for created and modified which are NULL.
> The add_document function is in the facilities_controller which looks
> like this:
>
> cake 1.2.3.166
>
> function admin_add_document($id = null){
>     if (empty($this->data)) {
>       $this->data = $this->Facility->findById($id);
>     } else {
>       if (is_uploaded_file($this->data['Document']['0']['File']
> ['tmp_name'])) {
>         $fileData = fread(fopen($this->data['Document']['0']['File']
> ['tmp_name'], "r"),
>                         $this->data['Document']['0']['File']['size']);
>         $this->data['Document']['facility_id']  = $this->Facility->id;
>         $this->data['Document']['name']         = $this->data
> ['Document']['0']['File']['name'];
>         $this->data['Document']['title']        = $this->data
> ['Document']['0']['title'];
>         $this->data['Document']['file_type']    = $this->data
> ['Document']['0']['File']['type'];
>         $this->data['Document']['size']         = $this->data
> ['Document']['0']['File']['size'];
>         $this->data['Document']['content']      = $fileData;
>
>         $this->Facility->Document->create();
>         if ($this->Facility->Document->save($this->data, array
> ('validate' => 'first'))) {
>           $this->Session->setFlash('The Document has been saved',
> 'flash_good');
>           $this->redirect(array('action'=>'view', $this->Facility->id));
>
>         }
>       } else {
>         $this->Session->setFlash('The Document for facility_id '.$id.'
> could not be saved.', 'flash_bad');
>       }
>     }
>
>   }
>
> The admin_add function that works looks like this:
>
> function admin_add() {
>     if (!empty($this->data)) {
>       if (is_uploaded_file($this->data['Document']['0']['File']
> ['tmp_name'])) {
>         $fileData = fread(fopen($this->data['Document']['0']['File']
> ['tmp_name'], "r"),
>                         $this->data['Document']['0']['File']['size']);
>         $this->data['Document']['0']['name']      = $this->data
> ['Document']['0']['File']['name'];
>         $this->data['Document']['0']['file_type'] = $this->data
> ['Document']['0']['File']['type'];
>         $this->data['Document']['0']['size']      = $this->data
> ['Document']['0']['File']['size'];
>         $this->data['Document']['0']['content']   = $fileData;
>
>         if ($this->Facility->saveAll($this->data, array('validate' =>
> 'first'))) {
>           $this->Session->setFlash('Saved Facility and uploaded
> Document.', 'flash_good');
>           $this->redirect(array('action'=>'view', $this->Facility->id));
>
>         }
>       } else {
>         if ($this->Facility->save($this->data)) {
>           $this->Session->setFlash('Saved Facility. No file
> uploaded.', 'flash_good');
>           $this->redirect(array('action'=>'view', $this->Facility->id));
>
>         }
>       }
>     }
>
> Can anyone point me in the right direction? I haven't been able to
> find much information on how exactly CakePHP automagically sets the
> values for these columns so if there's some good documentation this
> please let me know.
>
> Thanks in advance.
--~--~---------~--~----~------------~-------~--~----~
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