まず、テーブルの構造は次のようにする必要があります。
logins Table.
Id auto_increment
username
password userDetails Table.
Id auto_increment
user_id
name
address
etc... これで、各テーブルのモデルは次のようになります。
ログイン
<?php
class Login extends AppModel
{
var $name = 'User';
var $hasMany = array
(
'UserDetail' => array
(
'className' => 'UserDetail',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'exclusive' => '',
'finderQuery' => '',
'counterQuery' => ''
)
}
?> UserDetail
<?php
class UserDetail extends AppModel
{
var $name = 'UserDetail';
var $belongsTo = array
(
'User' => array
(
'className' => 'User',
'foreignKey' => 'user_id',
'dependent' => false,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => ''
)
}
?> そして最後に、ログインの詳細を取得する必要があるコントローラーで。
$login_detail = $this->Login->find('all');
結果の$login_detailにuserDetailテーブルレコードが表示されます .use
pr($login_detail); コントローラーで動作を確認します。 乾杯。お気軽にお問い合わせください。