Under the thinkphp-correlation model

Source: Internet
Author: User

Pair more: Has_many

Controller

<?php
namespace Home\controller;
Use Think\controller;

Class Glmoxcontroller extends Controller {
Public Function index () {
$user =d (' con ');
$arr = $user->relation (True)->select ();
Echo ' <pre> ';
Print_r ($arr);
Echo ' </pre> ';


}

}

?>

Model

<?php
namespace Home\model;
Use Thimk\model;
Use Think\model\relationmodel;


Class Glmxingmodel extends relationmodel{
Protected $_link = Array (
' Con ' = Array (


' Mapping_type ' + self::has_many,//sets the correlation mode, such as a one-to-many
' Foreign_key ' = ' uid ',///Associated foreign key name, auto-corresponding ID
' Class_name ' = ' Sfz ',//the model class name to associate, not write default above

' Mapping_name ' = ' contents ',//Modify the field name of the map
' Mapping_fields ' = ' con ',//Show con field only
' Mapping_limit ' = ' 0,2 ',//show only two
' Mapping_order ' + ' ID DESC ',//display with ID Countdown


),
);
}

?>

Many-to-many:

Association of user tables to role tables, intermediate tables

' User ' = = Array (
' Mapping_type ' + self::belongs_to,//set the correlation mode, such as one-to-one
' relation_table ' = ' think_group ',//full table name of the intermediate table
' Foreign_key ' = ' uid ',///Associated foreign key name, auto-corresponding ID
' Relation_foreign_key ' = ' gid ',//field associated with

),

Under the thinkphp-correlation model

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.