Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

\Phalcon\Mvc\Model->save($_POST, ...) not working. Bug?

I'm following the first tutorial and I'm having problems with the save() method. Here is the code:

//Store and check for errors
        if ($user->save($_POST, array('name', 'email')) == true) {
            echo "Thanks for register!";
        } else {
            echo "Sorry, the following problems were generated: ";
            foreach ($user->getMessages() as $message) {
                echo $message->getMessage(), "<br/>";
            }
        }

It doesn't work, it always present this error message:

Sorry, the following problems were generated: name is required email is required

But if I set the variables like this it works:

//Store and check for errors
$user->name = $_POST['name'];
$user->email = $_POST['email'];

        if ($user->save() == true) {
            echo "Thanks for register!";
        } else {
            echo "Sorry, the following problems were generated: ";
            foreach ($user->getMessages() as $message) {
                echo $message->getMessage(), "<br/>";
            }
        }

Any idea why this is happening? Is this a bug?



85.3k
Accepted
answer

It seems, we need to update the tutorial, the mass assignment is going to be removed due to potential possible security issues



21.4k

That's what I thought. Also the API docs need to be updated.