ThinkPHP/Library/Think/Model/ViewModel.class.php
(开头部分) 9KB这里只显示每个文件的开头 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 ViewModel extends Model {
protected $viewFields = array();
/**
* 自动检测数据表信息
* @access protected
* @return void
*/
protected function _checkTableInfo() {}
/**
* 得到完整的数据表名
* @access public
* @return string
*/
public function getTableName() {
if(empty($this->trueTableName)) {
$tableName = '';
foreach ($this->viewFields as $key=>$view){
// 获取数据表名称
if(isset($view['_table'])) { // 2011/10/17 添加实际表名定义支持 可以实现同一个表的视图
$tableName .= $view['_table'];
$prefix = $this->tablePrefix;
$tableName = preg_replace_callback("/__([A-Z_-]+)__/sU", function($match) use($prefix){ return $prefix.strtolower($match[1]);}, $tableName);
}else{
$class = $key.'Model';
$Model = class_exists($class)?new $class():M($key);
$tableName .= $Model->getTableName();
}
// 表别名定义
$tableName .= !empty($view['_as'])?' '.$view['_as']:' '.$key;
// 支持ON 条件定义
$tableName .= !empty($view['_on'])?' ON '.$view['_on']:'';
// 指定JOIN类型 例如 RIGHT INNER LEFT 下一个表有效
$type = !empty($view['_type'])?$view['_type']:'';
$tableName .= ' '.strtoupper($type).' JOIN ';
$len = strlen($type.'_JOIN ');
}
$tableName = substr($tableName,0,-$len);
$this->trueTableName = $tableName;
}
return $this->trueTableName;
}
后面还有 183 行代码,解锁后查看完整代码
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
