thinkphp Correlation Model
Two-Table association queries: Message and the User Association condition UID (Reference manual: Model--associated model)
Steps:
One: Create the message table Custom mode--->home\lib\model\messagemodel.class.php
<?php
Class Messagemodel extends relationmodel{
This is auto-populated
Protected $_auto=array (
Array (' Time ', ' time ', 1, ' function '),
Array (' uid ', ' getId ', 1, ' callback ')
);
This is the association model configuration
Protected $_link=array (
' User ' = = Array (
' Mapping_type ' =>belongs_to,
' Class_name ' = ' User ',
' Foreign_key ' = ' uid ',//foreign key
' Mapping_name ' = ' user ',
' Mapping_fields ' = ' username ',//username fields only
' As_fields ' = ' username:uname ',//and current table field display
If you're afraid of a conflict with 2 table fields, Username:uname will show up as uname.
),
);
protected function GetId () {
return $_session[' id '];
}
}
?>
Two: Controller
<?php
$message = D (' message ');
$arr = $message->relation (True)->select ();
Dump ($arr);
$this->assagin (' list ', $arr);
$this->display ();
?>
thinkphp correlation Model (20)