Problem with find in cake php

0

I have to make a query to a database and just to test if you ask me what I'm doing are some tests but it does not work for me

Customer Model     

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

App::uses('AppModel', 'Model');

/**
 * CakePHP Cliente
 * @author ingenieriaseadog
 */
class Cliente extends AppModel {
    public $validate = array(
        'id' => array(
            'rule' => 'notBlank'
        ),
        'empresa' => array(
            'rule' => 'notBlank'
        ),
        'cliente' => array(
            'rule' => 'notBlank'
        ),
        'direccion' => array(
            'rule' => 'notBlank'
        ),
        'telefono' => array(
            'rule' => 'notBlank'
        ),
        'informacion' => array(
            'rule' => 'notBlank'
        ),
        'horario' => array(
            'rule' => 'notBlank'
        )
    );
}

Controller , here's the problem, here I use the find and try to return what it brings me from the DB

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)) {
                $hola = $this->Cliente->find('all', array(
                    'fields' => array('id')));
                $this->Flash->success(__($hola));
                return $this->request->data;
            }
            $this->Flash->error(__('Unable to add your post.'));
        }
    }

Error taking out

Structure of the DB

    
asked by Andrés Vélez 26.03.2018 в 16:56
source

1 answer

0

Solution

$consult = $this->Cliente->find('all', array(
                    'conditions' => array('cliente LIKE ' => $client)));
                $id_client = $consult[0];

In $consult I save the query, which is equivalent to SELECT id FROM clientes AS Cliente WHERE cliente LIKE $client Where $client is a client name entered in a form for which I want to search for the id, in my case there are some clients that have the same name since I'm just in the trial version, so later a validation so that there is only one user with the same name, but for the moment you get the line of the first user with that name which is stored in $id_client and hence I return the id $this->Flash->success(__($client.var_dump($id_client['Client']['id']))); , but later it would be for make an insert in another table.

    
answered by 27.03.2018 / 00:35
source