Given handle of a specific field cakephp

0

I'm starting now with CakePHP, and I'd like to know how to get the value of a specific field.

For example, I have the name and email fields. How do I get the value of the field name?

PS: I know you have the method $this->data , but it takes all fields.

My form looks like this:

echo $this->Form->create('Usuario', array('action' => 'get'));
echo $this->Form->input('usuario');
echo $this->Form->input('email');
echo $this->Form->input('senha', array('type' => 'password'));
echo $this->Form->input('ativo');
echo $this->Form->end('Salvar');
    
asked by anonymous 09.12.2014 / 21:43

1 answer

1

It is not clear in what situation you want to take this data. If it is the value of the field after sending the form, this is usually done in Controller:

$usuario = $this->request->data['NomeDoModel']['usuario'];

If it is from the database, you query for the model (also from the Controller):

$usuario = $this->NomeDoModel->find('all', array(
    'fields' => 'usuario',
    'conditions' => "id = 1" // por exemplo
));
echo $usuario[0]['NomeDoModel']['usuario'];

In the view itself, if the data has been set to data from the Controler, you can access directly via:

$this->data['NomeDoModel']['usuario'];

Or pass in any variable. For example, inside your controller, action index :

function index() {
    this->set(array('dado' => 'bla bla bla'));
}

// e na view:
echo $dado;
    
10.12.2014 / 18:41