Re: Exclude Array Item on Save

2007-12-02 Thread Samuel DeVore

you can also use the $fieldList parameter in the $modelName->save

http://api.cakephp.org/1.2/class_model.html#ebe42ae387be89985b5a35dd428f5c81

Model::save (   $   data = null,
$   validate = true,
$   fieldList = array() 
)   
Saves model data to the database. By default, validation occurs before save.
Parameters:
array   $data Data to save.
boolean $validate If set, validation will be done before the save
array   $fieldList List of fields to allow to be written

On Dec 1, 2007 3:23 PM, Chris Hartjes <[EMAIL PROTECTED]> wrote:
>
> On Dec 1, 2007 4:54 PM, wilson <[EMAIL PROTECTED]> wrote:
> >
> > Hiya,
> >
> > I've got a simple image upload form in which the user can come back
> > and update the image, as well as name, description etc.
> >
> > The issue I'm having is that when they come back to only update the
> > description, I don't want the original image to be overridden.
> >
> > So I first thought that I could just unset the array item.  For
> > example:
> >
> > if (!$this->data['Home']['image']['name']) {
> > unset($this->data['Home']['image']);
> > }
> >
> > However, the Cake save() function still overrwrites the old image in
> > the DB.
> >
> > How do you all accomplish this in your forms?  Is there a CakePHP
> > syntax to tell it to not update a field?
>
>
> Try putting the code that unsets that element in the array in a
> beforeSave() method in the model.
>
>
> --
> Chris Hartjes
>
> My motto for 2007:  "Just build it, damnit!"
>
> @TheKeyboard - http://www.littlehart.net/atthekeyboard
>
>
> >
>



-- 
(the old fart) the advice is free, the lack of crankiness will cost you

- its a fine line between a real question and an idiot

http://blog.samdevore.com/archives/2007/03/05/when-open-source-bugs-me/

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Re: Exclude Array Item on Save

2007-12-01 Thread Chris Hartjes

On Dec 1, 2007 4:54 PM, wilson <[EMAIL PROTECTED]> wrote:
>
> Hiya,
>
> I've got a simple image upload form in which the user can come back
> and update the image, as well as name, description etc.
>
> The issue I'm having is that when they come back to only update the
> description, I don't want the original image to be overridden.
>
> So I first thought that I could just unset the array item.  For
> example:
>
> if (!$this->data['Home']['image']['name']) {
> unset($this->data['Home']['image']);
> }
>
> However, the Cake save() function still overrwrites the old image in
> the DB.
>
> How do you all accomplish this in your forms?  Is there a CakePHP
> syntax to tell it to not update a field?


Try putting the code that unsets that element in the array in a
beforeSave() method in the model.


-- 
Chris Hartjes

My motto for 2007:  "Just build it, damnit!"

@TheKeyboard - http://www.littlehart.net/atthekeyboard

--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---



Exclude Array Item on Save

2007-12-01 Thread wilson

Hiya,

I've got a simple image upload form in which the user can come back
and update the image, as well as name, description etc.

The issue I'm having is that when they come back to only update the
description, I don't want the original image to be overridden.

So I first thought that I could just unset the array item.  For
example:

if (!$this->data['Home']['image']['name']) {
unset($this->data['Home']['image']);
}

However, the Cake save() function still overrwrites the old image in
the DB.

How do you all accomplish this in your forms?  Is there a CakePHP
syntax to tell it to not update a field?

I'm using the latest 1.2x from the SVN.

Many thanks!
Wilson


--~--~-~--~~~---~--~~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to cake-php@googlegroups.com
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
-~--~~~~--~~--~--~---