ThinkPHP/Library/Think/Model/RelationModel.class.php
(开头部分) 22KB这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。
<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2014 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------
namespace Think\Model;
use Think\Model;
/**
* ThinkPHP关联模型扩展
*/
class RelationModel extends Model {
const HAS_ONE = 1;
const BELONGS_TO = 2;
const HAS_MANY = 3;
const MANY_TO_MANY= 4;
// 关联定义
protected $_link = array();
/**
* 动态方法实现
* @access public
* @param string $method 方法名称
* @param array $args 调用参数
* @return mixed
*/
public function __call($method,$args) {
if(strtolower(substr($method,0,8))=='relation'){
$type = strtoupper(substr($method,8));
if(in_array($type,array('ADD','SAVE','DEL'),true)) {
array_unshift($args,$type);
return call_user_func_array(array(&$this, 'opRelation'), $args);
}
}else{
return parent::__call($method,$args);
}
}
/**
* 得到关联的数据表名
* @access public
* @return string
*/
public function getRelationTableName($relation) {
$relationTable = !empty($this->tablePrefix) ? $this->tablePrefix : '';
$relationTable .= $this->tableName?$this->tableName:$this->name;
$relationTable .= '_'.$relation->getModelName();
return strtolower($relationTable);
}
// 查询成功后的回调方法
protected function _after_find(&$result,$options) {
// 获取关联数据 并附加到结果中
if(!empty($options['link']))
后面还有 352 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
