当我通过 find('all') 搜索数据时,它会得到这个返回数据:
Array (
[0] =>
Array (
[0] => /* why this is not the model name? */
Array (
[id] => 1
[username] => **
[password] => en
[memo] => **
)
)
)
我怎样才能得到这样的结果?
Array (
[0] =>
Array (
['User'] => /* use the model name? */
Array (
[id] => 1
[username] => **
[password] => en
[memo] => **
)
)
)
我发现另一个问题:
account table:
id username password
2 admin 123456
email table:
id title content account_id
1 test test email 2
像这样的模型: class Account extends AppModel { public $name = 'Account'; }
class Email extends AppModel{
public $name = 'Email';
public $belongsTo = array(
'Account' => array(
'className' => 'Account',
'foreignKey' => 'account_id'
)
);
}
所以我编码:
App::import('Model','Email');
$this->Email = new Email();
$result = $this->Email->find('all');
我得到的结果是:
Array (
[0] =>
Array (
[0] =>
Array (
[id] => 1
[username] => admin
[password] => 123456
[title] => test
[content] => test email
[account_id] => 1
)
)
)
为什么表的 id 在结果中Email
覆盖了Account
表的 id?
谁能告诉我我需要在我的 php 中安装哪些 php 开销?