0

I have the following code:

print_r( $this->request->data['User'] ['username'] );
print_r( $this->User->findByRole($this->request->data['User']['username']) );

Now as you can see this is just to test it but when i try to run this i get the username correctly ( the first print_r) but the second print_r returns an empty array.

I know that there is a field called Role in my user database i also know that it is not empty. it should return employee.

So what am i doing wrong?

4

1 回答 1

1

使用findByUsername并使用第二个参数来指定fields

$this->User->findByUsername($this->request->data['User']['username'],array("User.role"));

或标准方法:

$this->User->find("first",array(
    "fields" => array("User.role")
    ,"conditions" => array("User.username" => $this->request->data['User']['username'])
));
于 2013-08-12T11:11:06.120 回答