CActiveFinder

优质
小牛编辑
124浏览
2023-12-01
所有包 | 属性 | 方法
system.db.ar
继承class CActiveFinder » CComponent
源自1.0
版本$Id: CActiveFinder.php 3562 2012-02-13 01:27:06Z qiang.xue $
源码framework/db/ar/CActiveFinder.php
CActiveFinder实现贪婪加载和延迟加载的关系活动记录。

当使用贪婪加载时,此类提供了与 CActiveRecord相同的查询方法。

公共属性

隐藏继承属性

属性类型描述定义在
baseLimitedboolean基础模型有否限制或偏移。 在内部使用此属性CActiveFinder
joinAllboolean一次全部连接所有表。默认为false。 在内部使用此属性。CActiveFinder

公共方法

隐藏继承方法

方法描述定义在
__call()如果类中没有调的方法名,则调用这个方法。CComponent
__construct()构造函数。CActiveFinder
__get()返回一个属性值、一个事件处理程序列表或一个行为名称。CComponent
__isset()检查一个属性是否为null。CComponent
__set()设置一个组件的属性值。CComponent
__unset()设置一个组件的属性为null。CComponent
asa()返回这个名字的行为对象。CComponent
attachBehavior()附加一个行为到组件。CComponent
attachBehaviors()附加一个行为列表到组件。CComponent
attachEventHandler()为事件附加一个事件处理程序。CComponent
canGetProperty()确定属性是否可读。CComponent
canSetProperty()确定属性是否可写。CComponent
count()此方法在内部被调用。CActiveFinder
detachBehavior()从组件中分离一个行为。CComponent
detachBehaviors()从组件中分离所有行为。CComponent
detachEventHandler()分离一个存在的事件处理程序。CComponent
disableBehavior()禁用一个附加行为。CComponent
disableBehaviors()禁用组件附加的所有行为。CComponent
enableBehavior()启用一个附加行为。CComponent
enableBehaviors()启用组件附加的所有行为。CComponent
evaluateExpression()计算一个PHP表达式,或根据组件上下文执行回调。CComponent
findAllBySql()此方法在内部被调用。CActiveFinder
findBySql()此方法在内部被调用。CActiveFinder
getEventHandlers()返回一个事件的附加处理程序列表。CComponent
hasEvent()确定一个事件是否定义。CComponent
hasEventHandler()检查事件是否有附加的处理程序。CComponent
hasProperty()确定属性是否被定义。CComponent
lazyFind()查找指定活动记录的相关对象。CActiveFinder
query()不要调用这个方法。 此方法在内部使用以执行关联查询。CActiveFinder
raiseEvent()发起一个事件。CComponent

属性详细

baseLimited 属性 public boolean $baseLimited;

基础模型有否限制或偏移。 在内部使用此属性

joinAll 属性 public boolean $joinAll;

一次全部连接所有表。默认为false。 在内部使用此属性。

方法详细

__construct() 方法
public void __construct(CActiveRecord $model, mixed $with)
$modelCActiveRecord初始化active finding process的model
$withmixed实时查询的关系名
源码: framework/db/ar/CActiveFinder.php#45 (显示) publicfunction__construct($model,$with)
{
$this->_builder=$model->getCommandBuilder();
$this->_joinTree=newCJoinElement($this,$model);
$this->buildJoinTree($this->_joinTree,$with);
}

构造函数。 一个join树的建立基于声明的活动记录之间的关系。

count() 方法
public string count(CDbCriteria $criteria)
$criteriaCDbCriteria查询条件
{return}string
源码: framework/db/ar/CActiveFinder.php#146 (显示) publicfunctioncount($criteria)
{
Yii::trace(get_class($this->_joinTree->model).'.count()eagerly','system.db.ar.CActiveRecord');
$this->joinAll=$criteria->together!==true;

$alias=$criteria->alias===null?'t':$criteria->alias;
$this->_joinTree->tableAlias=$alias;
$this->_joinTree->rawTableAlias=$this->_builder->getSchema()->quoteTableName($alias);

$n=$this->_joinTree->count($criteria);
$this->destroyJoinTree();
return$n;
}

此方法在内部被调用。

findAllBySql() 方法
public CActiveRecord[] findAllBySql(string $sql, array $params=array ( ))
$sqlstringSQL 语句
$paramsarray绑定 SQL 语句的参数
{return}CActiveRecord[]
源码: framework/db/ar/CActiveFinder.php#122 (显示) publicfunctionfindAllBySql($sql,$params=array())
{
Yii::trace(get_class($this->_joinTree->model).'.findAllBySql()eagerly','system.db.ar.CActiveRecord');
if(($rows=$this->_builder->createSqlCommand($sql,$params)->queryAll())!==array())
{
$baseRecords=$this->_joinTree->model->populateRecords($rows,false);
$this->_joinTree->beforeFind(false);
$this->_joinTree->findWithBase($baseRecords);
$this->_joinTree->afterFind();
$this->destroyJoinTree();
return$baseRecords;
}
else
{
$this->destroyJoinTree();
returnarray();
}
}

此方法在内部被调用。

findBySql() 方法
public CActiveRecord findBySql(string $sql, array $params=array ( ))
$sqlstringSQL 语句
$paramsarray参数绑定到此 SQL 语句
{return}CActiveRecord
源码: framework/db/ar/CActiveFinder.php#100 (显示) publicfunctionfindBySql($sql,$params=array())
{
Yii::trace(get_class($this->_joinTree->model).'.findBySql()eagerly','system.db.ar.CActiveRecord');
if(($row=$this->_builder->createSqlCommand($sql,$params)->queryRow())!==false)
{
$baseRecord=$this->_joinTree->model->populateRecord($row,false);
$this->_joinTree->beforeFind(false);
$this->_joinTree->findWithBase($baseRecord);
$this->_joinTree->afterFind();
$this->destroyJoinTree();
return$baseRecord;
}
else
$this->destroyJoinTree();
}

此方法在内部被调用。

lazyFind() 方法
public void lazyFind(CActiveRecord $baseRecord)
$baseRecordCActiveRecord要被载入的基本记录相关对象
源码: framework/db/ar/CActiveFinder.php#165 (显示) publicfunctionlazyFind($baseRecord)
{
$this->_joinTree->lazyFind($baseRecord);
if(!empty($this->_joinTree->children))
{
$child=reset($this->_joinTree->children);
$child->afterFind();
}
$this->destroyJoinTree();
}

查找指定活动记录的相关对象。 该方法在内部被CActiveRecord触发,支持懒惰加载.

query() 方法
public mixed query(CDbCriteria $criteria, boolean $all=false)
$criteriaCDbCriteria该数据库条件
$allboolean是否带回所有记录
{return}mixed查询结果
源码: framework/db/ar/CActiveFinder.php#59 (显示) publicfunctionquery($criteria,$all=false)
{
$this->joinAll=$criteria->together===true;
$this->_joinTree->beforeFind(false);

if($criteria->alias!='')
{
$this->_joinTree->tableAlias=$criteria->alias;
$this->_joinTree->rawTableAlias=$this->_builder->getSchema()->quoteTableName($criteria->alias);
}

$this->_joinTree->find($criteria);
$this->_joinTree->afterFind();

if($all)
{
$result=array_values($this->_joinTree->records);
if($criteria->index!==null)
{
$index=$criteria->index;
$array=array();
foreach($resultas$object)
$array[$object->$index]=$object;
$result=$array;
}
}
elseif(count($this->_joinTree->records))
$result=reset($this->_joinTree->records);
else
$result=null;

$this->destroyJoinTree();
return$result;
}

不要调用这个方法。 此方法在内部使用以执行关联查询。 基于给定的数据库条件。