thinkphp correlation Model (20)

Source: Internet
Author: User

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)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.