On 04/08/07, pbland <[EMAIL PROTECTED]> wrote:
>
> I've spent the last 2 days trying to get my save() to work with no
> luck. I've reviewed everything. Twice. I've checked this group for
> things to look for and everything looks correct. I've printed my model
> and it has the data:
>
> Array
> (
>     [Account] => Array
>         (
>             [first_name] => Joe
>             [last_name] => Tester
>         )
> )
>
> Here's my database schema:
>
> CREATE TABLE accounts (
>  id             INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
>  first_name     VARCHAR(30) NOT NULL,
>  last_name      VARCHAR(50) NOT NULL,
>  created                DATETIME DEFAULT NULL,
>  modified               DATETIME DEFAULT NULL)
>
> And my controller:
>
> class AccountsController extends AppController {
> var $name = 'Accounts';
> function create() {
>    pr($this-data);
>    if($this->Account->save($this->data)) {
>       echo 'save successful';
>    else
>       echo 'no good';
> }
> }
>
> I don't have any redirects. I have debug at 2 and I don't see any
> INSERT statement, nor any error messages.
>
> Does anyone have some other things for me to check?

you need to check that the data's there before saving, have you gone
through the blog tutorial??

here's what you need anyway...

<?php

class AccountsController extends AppController
{
        var $name = 'Accounts';

        function create()
        {
                // first, check if form has been submitted, if not, render form 
view
                if (empty($this->data))
                {
                        $this->render();
                }
                // form has been submitted
                else
                {
                        // so attempt to save data
                        if ($this->Account->save($this->data))
                        {
                                // SAVE SUCCESSFUL
                        // inform user using cake's flash() method, see api for 
details
                                $this->flash('your data has been saved', '/');
                        }
                        else
                        {
                                // SAVE UNSUCESSFUL
                                // validate model errors
                                $this->validateErrors($this->Account);
                                // pass data back to view
                                $this->set('data', $this->data);
                                // render form again
                                $this->render();
                        }
                }
        }
}

?>

hth

jon


-- 

jon bennett
w: http://www.jben.net/
iChat (AIM): jbendotnet Skype: jon-bennett

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to