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