Sunday, July 25, 2010

Re: Notice (8): Undefined index: firstname [APP\controllers\users_controller.php, line 45]

hey cricket, thx. it makes sense. but if i code

if (!empty($this->data))
{

if ($this->User->save($this->data))
{
$this->Session->setFlash('Profil aktualisiert');
$this->redirect(array('controller' => 'users', 'action' =>
'profile'));
}
else{
$this->Session->setFlash('Speichern fehlgeschlagen');
$this->redirect(array('controller' => 'users', 'action' =>
'editprofile'));
}
}

cake inserts a complete new data in my table and does not update the
on that is edited. the error occurs not though :)

but in case

On 25 Jul., 19:21, cricket <zijn.digi...@gmail.com> wrote:
> On Sun, Jul 25, 2010 at 12:39 PM, Tomfox Wiranata
>
> <tomfox.wiran...@gmail.com> wrote:
> > that is not correct?
>
> > i try to access the information in the form with this->data and assign
> > these to my database field with $updates:
>
> > if i code:
> >               $updates['User']['firstname']= "test";
> >                $updates['User']['lastname']= "test_lastname";
>
> > cake stores "test" in my database in "firstname" and "test_lastname"
> > in "lastname".... so you might be right, sth is wrong with this-
> >>data..but what is correcT?
>
> Oh, I just looked at that more carefully. It's a bit confusing because
> you've got this $updates var that seems to be completely unnecessary.
> Your controller method should look more like this:
>
> function updateProfile()
> {
>         /* check if form was submitted
>          */
>         if (!empty($this->data))
>         {
>                 /* now save the submitted data
>                  */
>                 if ($this->User->save($this->data))
>                 {
>
> Without the test to see if $this->data is empty, that code would run
> the first time you load the page. So, $this->data['User']['firstname']
> does not exist. It's important to remember that, where forms are
> involved, Cake runs the method/action twice.

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 cake-php@googlegroups.com
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?hl=en

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate