Yii Framework v1.1.10 绫诲弬鑰

CActiveFinder

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鐩稿悓鐨勬煡璇㈡柟娉曘

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
baseLimited boolean 鍩虹妯″瀷鏈夊惁闄愬埗鎴栧亸绉汇 鍦ㄥ唴閮ㄤ娇鐢ㄦ灞炴 CActiveFinder
joinAll boolean 涓娆″叏閮ㄨ繛鎺ユ墍鏈夎〃銆傞粯璁や负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() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 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)
$model CActiveRecord 鍒濆鍖朼ctive finding process鐨刴odel
$with mixed 瀹炴椂鏌ヨ鐨勫叧绯诲悕
婧愮爜锛 framework/db/ar/CActiveFinder.php#45 (鏄剧ず)
public function __construct($model,$with)
{
    
$this->_builder=$model->getCommandBuilder();
    
$this->_joinTree=new CJoinElement($this,$model);
    
$this->buildJoinTree($this->_joinTree,$with);
}

鏋勯犲嚱鏁般 涓涓猨oin鏍戠殑寤虹珛鍩轰簬澹版槑鐨勬椿鍔ㄨ褰曚箣闂寸殑鍏崇郴銆

count() 鏂规硶
public string count(CDbCriteria $criteria)
$criteria CDbCriteria 鏌ヨ鏉′欢
{return} string
婧愮爜锛 framework/db/ar/CActiveFinder.php#146 (鏄剧ず)
public function count($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 ( ))
$sql string SQL 璇彞
$params array 缁戝畾 SQL 璇彞鐨勫弬鏁
{return} CActiveRecord[]
婧愮爜锛 framework/db/ar/CActiveFinder.php#122 (鏄剧ず)
public function findAllBySql($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();
        return array();
    }
}

姝ゆ柟娉曞湪鍐呴儴琚皟鐢ㄣ

findBySql() 鏂规硶
public CActiveRecord findBySql(string $sql, array $params=array ( ))
$sql string SQL 璇彞
$params array 鍙傛暟缁戝畾鍒版 SQL 璇彞
{return} CActiveRecord
婧愮爜锛 framework/db/ar/CActiveFinder.php#100 (鏄剧ず)
public function findBySql($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)
$baseRecord CActiveRecord 瑕佽杞藉叆鐨勫熀鏈褰曠浉鍏冲璞
婧愮爜锛 framework/db/ar/CActiveFinder.php#165 (鏄剧ず)
public function lazyFind($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)
$criteria CDbCriteria 璇ユ暟鎹簱鏉′欢
$all boolean 鏄惁甯﹀洖鎵鏈夎褰
{return} mixed 鏌ヨ缁撴灉
婧愮爜锛 framework/db/ar/CActiveFinder.php#59 (鏄剧ず)
public function query($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(
$result as $object)
                
$array[$object->$index]=$object;
            
$result=$array;
        }
    }
    else if(
count($this->_joinTree->records))
        
$result reset($this->_joinTree->records);
    else
        
$result null;

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

涓嶈璋冪敤杩欎釜鏂规硶銆 姝ゆ柟娉曞湪鍐呴儴浣跨敤浠ユ墽琛屽叧鑱旀煡璇€ 鍩轰簬缁欏畾鐨勬暟鎹簱鏉′欢銆

Copyright © 2008-2011 by Yii Software LLC
All Rights Reserved.