English 中文(简体)
CakePHP 1.3 controller save() does not save data
原标题:

I want to add a new user to the database, and do so by making them fill in a form and submitting this. All seems to work fine. Just before my save() call in the controller I return all data and all necessary data is there. It is valid(ated), since no errors are returned.

But then nothing happens. I m being returned to my form without any errors being shown. This is my save-line :

if($this->Registratie->save($this->data)) {

I m not making use of any beforeSave() methods.

Using debug($this->validationErrors); shows:

app/controllers/registratie_controller.php (line 45)

Which is the line of code from above.

I ve been going through my code over and over. What could the problem be?

问题回答

When you create a form using the FormHelper it will generate input names like:

<input type= text  name= data[Registratie][first_name] >

Once the form is submitted cake will push that into the $this->data array with an index of Registratie

You probably need to pass the index to the model when saving

if ($this->Registratie->save( $this->data[ Registratie ] ) ) {

I would also do a var_dump($this->data) or print_r($this->data) to make sure your form fields are coming through.

I had the same problem, fixed doing exactly what Jack B Nimble told. Using CakePHP 1.3

Sample:

Model: Contacts

$this->data[ contact ]




相关问题
PHP Framework: Ebay Like Site

I am going to be builiding a site like ebay - with all the features of ebay. Please note my payment method is limited to paypal. What would be the best PHP framework to use to build this quickly, ...

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

Using DISTINCT in a CakePHP find function

I am writing a CakePHP 1.2 app. I have a list of people that I want the user to be able to filter on different fields. For each filterable field, I have a drop down list. Choose the filter ...

Assistance with CakePHP model relationships

How would I represent the following in a CakePHP model? Product ======= product_id .... Cart ==== cart_id .... Carts_Products ============== cart_id product_id quantity

Prevent controller from trying to autoload model

I am a beginning Cake user and trying to do some work on an already existing application. Running into a problem when I create a new controller. I have created StoreController and when I try to call ...

热门标签