Jamille Aligan
Jamille Aligan

Reputation: 11

having problems since recreating my database

I have a controller on my Api folder named CrudsController and I have this function. what I don't understand is this is properly working before I had issues with my database that I had to recreate. Now I'm getting this error message:

Missing Method in CrudsController Error: The action api_add is not defined in controller CrudsController

> public function add()
>         {
> if ($this->request->is('post')) {
>                 $this->Crud->create();
> if ($this->Crud->save($this->request->data)) {
> 
> if (isset($this->request->data['Crud']) && isset($this->request->data['Crud']['email'])) {
> 
>                         $email = new CakeEmail('default'); // Use the 'default' configuration
> 
> Specify the from address as '[email protected]'
>                     $email->from(array('[email protected]' => 'Your Application'))
>                           ->replyTo('[email protected]') // Set the "Reply-To" header to no-reply address
>                           ->to($this->request->data['Crud']['email'])
>                           ->subject('Notification')
>                           ->send('Your data has been successfully saved.');
> 
> Debug statement
>                     $this->log('Email sent to: ' . $this->request->data['Crud']['email'], 'debug');
> else {
> Debug statement
>                     $this->log('Email not sent: Email address not found in request data', 'debug');
>                 }
> 
>                 $response = array(
>                     'ok' => true,
>                     'msg' => 'saved!',
>                     'data' => $this->request->data,
>                 );
> else {
>                 $response = array(
>                     'ok' => false,
>                     'msg' => 'not saved!',
>                     'data' => $this->request->data,
>                 );
>             }
> 
>             $this->set(array(
>                 'response' => $response,
>                 '_serialize' => 'response'
>             ));
>         }
>     }

I tried editing it to public function api_add. but after that this is the error I'm getting. I just want it to work the way it did before

Database Error Error: SQLSTATE[23000]: Integrity constraint violation: 1452 Cannot add or update a child row: a foreign key constraint fails (ednc.cruds, CONSTRAINT cruds_ibfk_1 FOREIGN KEY (status_id) REFERENCES statuses (id))

Upvotes: 1

Views: 35

Answers (0)

Related Questions