我有这个奇怪的问题;我无法从我的数据库中检索电子邮件。我尝试使用findByEmail,但我得到一个空数组。我尝试使用find('first')将电子邮件作为条件,但也获得了一个空数组。我可以检索除电子邮件之外的所有内容。
我的UsersController代码:$user = $this->User->findByEmail($this->data['User']['email']);
测试我试过的功能:`
$me = 'variasoft@gmail.com';
$user = $this->User->findByEmail($me);
debug($me);
debug()返回一个空数组。
我不确定问题是什么。
`
答案 0 :(得分:1)
问题与使用的编码有关。我最初使用armscii8_bin作为编码,当我更改为utf8_unicode_ci时,变量$ users在我使用以下代码时被填充:
if (!empty($this->request->data['User']['email'])) {
$user = $this->User->findByEmail($this->data['User']['email']);
结果:array(
'User' => array(
'password' => '*****',
'id' => '534395',
'parent_id' => '534394',
'created' => '2014-05-07 13:01:10',
'modified' => '2014-05-07 13:01:10',
'lastlogin' => '0000-00-00 00:00:00',
'first_name' => 'ascsadasd',
'last_name' => 'sadascascsa',
'middle_name' => 'saas',
'email' => 'variasoft@gmail.com',
'phone' => '0',
'country' => '',
'username' => 'trayvon',
'activation_code' => '',
'status' => false,
'password_reset' => '',
'tokenhash' => '',
'role' => '#artiste',
'reset_password_token' => '',
'token_created_at' => '',
'summary' => 'dvdsvsdfv ',
'role_model' => 'dsfv sdfvv dsfv sdv ',
'fav_song' => 'dsdv sddsfsd',
'trailer' => 'vdssdvddsds',
'genre_id' => '5',
'image' => null
),
'Parent' => array(
'password' => '*****',
'id' => '534394',
'parent_id' => null,
'created' => '2014-05-07 12:35:01',
'modified' => '2014-05-07 12:56:03',
'lastlogin' => '0000-00-00 00:00:00',
'first_name' => 'safasfs',
'last_name' => 'fasfasfcasf',
'middle_name' => 'safasfasfasf',
'email' => 'herrhorace@gmail.com',
'phone' => '123456',
'country' => '',
'username' => 'Memrise2',
'activation_code' => '',
'status' => false,
'password_reset' => '',
'tokenhash' => '',
'role' => 'manager',
'reset_password_token' => '',
'token_created_at' => '',
'summary' => null,
'role_model' => null,
'fav_song' => null,
'trailer' => null,
'genre_id' => null,
'image' => null
),
'Genre' => array(
'id' => '5',
'name' => 'Soul'
),
'Children' => array(),
'Image' => array(),
'Like' => array(),
'Comment' => array(),
'Customize' => array()
)