Problem with insert in cakephp-mysql

0

Driver code

    public function fullClient() {

//        $information = $this->data['Cliente']['informacio'];
        $client = $this->data['Cliente']['cliente'];
        //$posicion_coincidencia = strrpos($cadena_de_texto, $cadena_buscada, -20);
//        $this->Flash->error(__($hola));
        $this->loadModel('Cliente');
        if ($this->request->is('post')) {
            $this->Cliente->create();
            if ($this->Cliente->save($this->request->data)) {
                $consult = $this->Cliente->find('all', array(
                    'conditions' => array('cliente LIKE ' => $client)));
                $id_client = $consult[0];
                $data=array('procesos_id'=>'111',
                    'clientes_id'=>$id_client,
                    'fecha' => getdate());

                $this->loadModel('Necesidad');
                $this->Necesidad->save($data);
                $this->Flash->success(__($client.var_dump("hola")));

                return $this->request->data;
            }
            $this->Flash->error(__('Unable to add your post.'));
        }
    }

The model is called Necessity.php and the table in the database is called needs, but when you try to insert the following error comes out:

    
asked by Andrés Vélez 27.03.2018 в 00:39
source

1 answer

0

Apparently the problem is how CakePHP is translating the word Necessity into the plural.
For example if I run the following code

echo Inflector::tableize('Necesidad');

Prints the word necesidads .

Add this line to your file Necesidad.php

class Necesidad extends AppModel {
    public $useTable = 'necesidades'; // Agregamos esta linea con el nombre de la tabla en la base de datos
}
    
answered by 27.03.2018 / 01:36
source