user1323326
user1323326

Reputation:

How a transfer data from the model in the controller CakePHP?

How a transfer data from the model in the controller CakePHP ?

A have a method in model User:

public function reminderLogin() {
    $login = $this->data['User']['login'];
    $data = $this->find('first', array('fields' => array('username','email'),
            'conditions' => array('username' => $login)));
    if(!empty($data)) {
        print_r($data);
    }

}

Нow to take a $data variable in the controller?

Upvotes: 0

Views: 175

Answers (2)

geon
geon

Reputation: 8469

To illustrate the answer by dr Hannibal Lecter:

In your model:

public function reminderLogin() {
    $login = $this->data['User']['login'];
    $data = $this->find('first', array('fields' => array('username','email'),
            'conditions' => array('username' => $login)));

    return $data;
}

And in the controller action:

$data = $this->User->reminderLogin();
if(!empty($data)) {
    print_r($data);
}

Upvotes: 2

dr Hannibal Lecter
dr Hannibal Lecter

Reputation: 6721

Simply do a return $data; to get the data in your controller.

Upvotes: 0

Related Questions