Yii Framework v1.1.10 绫诲弬鑰

CActiveRecord

system.db.ar
缁ф壙 abstract class CActiveRecord » CModel » CComponent
瀹炵幇 ArrayAccess, Traversable, IteratorAggregate
婧愯嚜 1.0
鐗堟湰 $Id: CActiveRecord.php 3533 2012-01-08 22:07:55Z mdomba $
婧愮爜 framework/db/ar/CActiveRecord.php
CActiveRecord浠h〃鍏崇郴鏁版嵁鐨勭被鐨勫熀绫汇

瀹冨疄鐜颁簡娲诲姩璁板綍璁捐妯″紡锛屼竴绉嶆祦琛岀殑瀵硅薄鍏崇郴鏄犲皠锛圤RM锛夋妧鏈 璇风偣鍑the Guide鏇村鍏充簬杩欎釜绫荤殑 璇︾粏淇℃伅銆

鍏叡灞炴

闅愯棌缁ф壙灞炴

灞炴绫诲瀷鎻忚堪瀹氫箟鍦
attributes array 杩斿洖鎵鏈夊垪鐨勫睘鎬у笺 CActiveRecord
commandBuilder CDbCommandBuilder 杩斿洖姝R鐨勫懡浠ょ敓鎴愬櫒銆 CActiveRecord
db CDbConnection 鎵鏈夋椿鍔ㄨ褰曠被鐨勯粯璁ゆ暟鎹簱杩炴帴銆 榛樿鎯呭喌涓嬶紝杩欐槸'db'搴旂敤绋嬪簭缁勪欢锛 CActiveRecord
dbConnection CDbConnection 杩斿洖娲诲姩璁板綍鎵浣跨敤鐨勬暟鎹簱杩炴帴銆 CActiveRecord
dbCriteria CDbCriteria 杩斿洖鍜岃繖涓ā鍨嬬浉鍏崇殑鏌ヨ鏉′欢銆 CActiveRecord
errors array Returns the errors for all attribute or a single attribute. CModel
isNewRecord boolean 杩斿洖褰撳墠璁板綍鏄惁鏄柊鐨勩 CActiveRecord
iterator CMapIterator Returns an iterator for traversing the attributes in the model. CModel
metaData CActiveRecordMetaData 杩斿洖杩欎釜AR鐨勫厓鏁版嵁銆 CActiveRecord
oldPrimaryKey mixed 杩斿洖鏃х殑涓婚敭鍊笺 CActiveRecord
primaryKey mixed 杩斿洖涓婚敭鍊笺 CActiveRecord
safeAttributeNames array Returns the attribute names that are safe to be massively assigned. CModel
scenario string Returns the scenario that this model is used in. CModel
tableAlias string 杩斿洖鐢 find 鏂规硶浣跨敤琛ㄧ殑鍒悕銆 CActiveRecord
tableSchema CDbTableSchema 杩斿洖琛ㄧ殑鍏冩暟鎹紝杩欏睘浜嶢R绫汇 CActiveRecord
validatorList CList Returns all the validators declared in the model. CModel
validators array Returns the validators applicable to the current scenario. CModel

鍏叡鏂规硶

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
__call() 鍥炶皟鐨勫懡鍚嶆柟娉曘 CActiveRecord
__construct() 鏋勯犲嚱鏁般 CActiveRecord
__get() PHP getter 榄旀湳鏂规硶銆 CActiveRecord
__isset() 妫娴嬩竴涓睘鎬у兼槸鍚︿负null銆 CActiveRecord
__set() PHP setter 榄旀湳鏂规硶銆 CActiveRecord
__sleep() PHP sleep 榄旀湳鏂规硶銆 CActiveRecord
__unset() 妫鏌ュ睘鎬у兼槸鍚︿负绌恒 CActiveRecord
addError() Adds a new error to the specified attribute. CModel
addErrors() Adds a list of errors. CModel
addRelatedRecord() 涓嶈皟鐢ㄦ鏂规硶銆傛鏂规硶鐢ㄤ簬鍐呴儴CActiveFinder鏉ュ~鍏呯浉鍏崇殑瀵硅薄銆 CActiveRecord
afterFindInternal() 璋冪敤afterFind CActiveRecord
applyScopes() 閫傜敤浜庣粰瀹氭潯浠剁殑鏌ヨ鑼冨洿銆 CActiveRecord
asa() 杩斿洖杩欎釜鍚嶅瓧鐨勮涓哄璞° CComponent
attachBehavior() 闄勫姞涓涓涓哄埌缁勪欢銆 CComponent
attachBehaviors() 闄勫姞涓涓涓哄垪琛ㄥ埌缁勪欢銆 CComponent
attachEventHandler() 涓轰簨浠堕檮鍔犱竴涓簨浠跺鐞嗙▼搴忋 CComponent
attributeLabels() Returns the attribute labels. CModel
attributeNames() 杩斿洖妯″瀷鐨勬墍鏈夊睘鎬у悕绉扮殑鍒楄〃銆 CActiveRecord
beforeFindInternal() 璋冪敤beforeFind CActiveRecord
behaviors() Returns a list of behaviors that this model should behave as. CModel
cache() 璁剧疆鍏充簬鏌ヨ缂撳瓨鐨勫弬鏁. CActiveRecord
canGetProperty() 纭畾灞炴ф槸鍚﹀彲璇汇 CComponent
canSetProperty() 纭畾灞炴ф槸鍚﹀彲鍐欍 CComponent
clearErrors() Removes errors for all attributes or a single attribute. CModel
count() 鏌ユ壘婊¤冻鎸囧畾鏌ヨ鏉′欢鐨勮鏁般 CActiveRecord
countByAttributes() 鏌ユ壘鍏锋湁鎸囧畾鐨勫睘鎬у肩殑琛屾暟銆 CActiveRecord
countBySql() 鏌ユ壘鎸囧畾SQL璇彞褰卞搷鐨勮鏁般 CActiveRecord
createValidators() Creates validator objects based on the specification in rules. CModel
defaultScope() 杩斿洖榛樿鐨勫懡鍚嶈寖鍥达紝搴旈殣鍚繖绉嶆ā寮忛傜敤浜庢墍鏈夋煡璇€ CActiveRecord
delete() 鍒犻櫎瀵瑰簲浜庢娲诲姩璁板綍鐨勮銆 CActiveRecord
deleteAll() 鍒犻櫎鎸囧畾鏉′欢鐨勮銆 CActiveRecord
deleteAllByAttributes() 鍒犻櫎鎸囧畾鐨勫睘鎬у肩浉鍖归厤鐨勮銆 CActiveRecord
deleteByPk() 鍒犻櫎鎸囧畾涓婚敭鐨勮銆 CActiveRecord
detachBehavior() 浠庣粍浠朵腑鍒嗙涓涓涓恒 CComponent
detachBehaviors() 浠庣粍浠朵腑鍒嗙鎵鏈夎涓恒 CComponent
detachEventHandler() 鍒嗙涓涓瓨鍦ㄧ殑浜嬩欢澶勭悊绋嬪簭銆 CComponent
disableBehavior() 绂佺敤涓涓檮鍔犺涓恒 CComponent
disableBehaviors() 绂佺敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
enableBehavior() 鍚敤涓涓檮鍔犺涓恒 CComponent
enableBehaviors() 鍚敤缁勪欢闄勫姞鐨勬墍鏈夎涓恒 CComponent
equals() 褰撳墠娲诲姩璁板綍涓庡彟涓涓瘮杈冦 CActiveRecord
evaluateExpression() 璁$畻涓涓狿HP琛ㄨ揪寮忥紝鎴栨牴鎹粍浠朵笂涓嬫枃鎵ц鍥炶皟銆 CComponent
exists() 妫鏌ユ槸鍚︽弧瓒虫寚瀹氭潯浠剁殑琛屻 CActiveRecord
find() 鏌ユ壘鎸囧畾鏉′欢鐨勫崟涓椿鍔ㄨ褰曘 CActiveRecord
findAll() 鏌ユ壘婊¤冻鎸囧畾鏉′欢鐨勬墍鏈夋椿鍔ㄨ褰曘 CActiveRecord
findAllByAttributes() 鏌ユ壘鍏锋湁鎸囧畾灞炴у肩殑鎵鏈夋椿鍔ㄨ褰曘 CActiveRecord
findAllByPk() 鏌ユ壘鎸囧畾涓婚敭鐨勬墍鏈夋椿鍔ㄨ褰曘 CActiveRecord
findAllBySql() 鏌ユ壘鎸囧畾SQL璇彞鐨勬墍鏈夋椿鍔ㄨ褰曘 CActiveRecord
findByAttributes() 鏌ユ壘鍏锋湁鎸囧畾灞炴у肩殑鍗曚釜娲诲姩璁板綍銆 CActiveRecord
findByPk() 鏌ユ壘鎸囧畾涓婚敭鐨勫崟涓娲诲姩璁板綍銆 CActiveRecord
findBySql() 鏌ユ壘鎸囧畾SQL璇彞鐨勫崟涓椿鍔ㄨ褰曘 CActiveRecord
generateAttributeLabel() Generates a user friendly attribute label. CModel
getActiveRelation() 杩斿洖姝R绫诲0鏄庣殑鍛藉悕鍏崇郴銆 CActiveRecord
getAttribute() 杩斿洖鍛藉悕鐨勫睘鎬у笺 CActiveRecord
getAttributeLabel() 杩斿洖鎸囧畾灞炴х殑鏂囨湰鏍囩銆 CActiveRecord
getAttributes() 杩斿洖鎵鏈夊垪鐨勫睘鎬у笺 CActiveRecord
getCommandBuilder() 杩斿洖姝R鐨勫懡浠ょ敓鎴愬櫒銆 CActiveRecord
getDbConnection() 杩斿洖娲诲姩璁板綍鎵浣跨敤鐨勬暟鎹簱杩炴帴銆 CActiveRecord
getDbCriteria() 杩斿洖鍜岃繖涓ā鍨嬬浉鍏崇殑鏌ヨ鏉′欢銆 CActiveRecord
getError() Returns the first error of the specified attribute. CModel
getErrors() Returns the errors for all attribute or a single attribute. CModel
getEventHandlers() 杩斿洖涓涓簨浠剁殑闄勫姞澶勭悊绋嬪簭鍒楄〃銆 CComponent
getIsNewRecord() 杩斿洖褰撳墠璁板綍鏄惁鏄柊鐨勩 CActiveRecord
getIterator() Returns an iterator for traversing the attributes in the model. CModel
getMetaData() 杩斿洖杩欎釜AR鐨勫厓鏁版嵁銆 CActiveRecord
getOldPrimaryKey() 杩斿洖鏃х殑涓婚敭鍊笺 CActiveRecord
getPrimaryKey() 杩斿洖涓婚敭鍊笺 CActiveRecord
getRelated() 杩斿洖鐩稿叧鐨勮褰曘 CActiveRecord
getSafeAttributeNames() Returns the attribute names that are safe to be massively assigned. CModel
getScenario() Returns the scenario that this model is used in. CModel
getTableAlias() 杩斿洖鐢 find 鏂规硶浣跨敤琛ㄧ殑鍒悕銆 CActiveRecord
getTableSchema() 杩斿洖琛ㄧ殑鍏冩暟鎹紝杩欏睘浜嶢R绫汇 CActiveRecord
getValidatorList() Returns all the validators declared in the model. CModel
getValidators() Returns the validators applicable to the current scenario. CModel
hasAttribute() 妫鏌ユAR鏄惁鏈夊懡鍚嶇殑灞炴с CActiveRecord
hasErrors() Returns a value indicating whether there is any validation error. CModel
hasEvent() 纭畾涓涓簨浠舵槸鍚﹀畾涔夈 CComponent
hasEventHandler() 妫鏌ヤ簨浠舵槸鍚︽湁闄勫姞鐨勫鐞嗙▼搴忋 CComponent
hasProperty() 纭畾灞炴ф槸鍚﹁瀹氫箟銆 CComponent
hasRelated() 杩斿洖涓涓硷紝璇ュ兼寚绀烘槸鍚﹀凡鍔犺浇鍛藉悕鐨勭浉鍏冲璞° CActiveRecord
init() 鍒濆鍖栬繖涓ā鍨嬨 CActiveRecord
insert() 鎻掑叆涓琛屽埌鍩轰簬杩欎釜ActiveRecord鐨勫睘鎬ц〃銆 CActiveRecord
isAttributeRequired() Returns a value indicating whether the attribute is required. CModel
isAttributeSafe() Returns a value indicating whether the attribute is safe for massive assignments. CModel
model() 杩斿洖鎸囧畾AR绫荤殑闈欐佹ā鍨嬨 CActiveRecord
offsetExists() 杩斿洖鏄惁鏈夋寚瀹氬亸绉婚噺鐨勫厓绱犮 CActiveRecord
offsetGet() Returns the element at the specified offset. CModel
offsetSet() Sets the element at the specified offset. CModel
offsetUnset() Unsets the element at the specified offset. CModel
onAfterConstruct() This event is raised after the model instance is created by new operator. CModel
onAfterDelete() 鍦ㄥ垹闄よ褰曚箣鍚庯紝灏嗗紩鍙戞浜嬩欢銆 CActiveRecord
onAfterFind() 寮曞彂姝や簨浠惰褰曞悗鎵惧埌鏂规硶鐨勫疄渚嬨 CActiveRecord
onAfterSave() 淇濆瓨璁板綍涔嬪悗锛屽皢寮曞彂姝や簨浠躲 CActiveRecord
onAfterValidate() This event is raised after the validation is performed. CModel
onBeforeDelete() 鍦ㄥ垹闄よ褰曚箣鍓嶏紝灏嗗紩鍙戞浜嬩欢銆 CActiveRecord
onBeforeFind() AR finder鎵ц鏌ユ壘璋冪敤涔嬪墠锛屽皢寮曞彂姝や簨浠躲 CActiveRecord
onBeforeSave() 淇濆瓨璁板綍涔嬪墠锛屽皢寮曞彂姝や簨浠躲 CActiveRecord
onBeforeValidate() This event is raised before the validation is performed. CModel
onUnsafeAttribute() This method is invoked when an unsafe attribute is being massively assigned. CModel
populateRecord() 缁欐寚瀹氱殑灞炴у垱寤烘椿鍔ㄨ褰 CActiveRecord
populateRecords() 鍒涘缓鍩轰簬杈撳叆鏁版嵁鐨勬椿鍔ㄨ褰曠殑鍒楄〃銆 CActiveRecord
primaryKey() 杩斿洖鐩稿叧鏁版嵁搴撹〃鐨勪富閿 CActiveRecord
raiseEvent() 鍙戣捣涓涓簨浠躲 CComponent
refresh() 鏈鏂扮殑鏁版嵁灏嗚濉厖鍒拌繖涓椿鍔ㄨ褰曘 CActiveRecord
refreshMetaData() 鍒锋柊杩欎釜AR绫荤殑鍏冩暟鎹 CActiveRecord
relations() 鐢虫槑鍏崇郴鐨勫璞★紝搴旈噸鍐欐鏂规硶銆 CActiveRecord
resetScope() 閲嶇疆鎵鏈夊彉閲忎綔鐢ㄥ煙锛屽寘鎷粯璁ょ殑鑼冨洿銆 CActiveRecord
rules() Returns the validation rules for attributes. CModel
save() 淇濆瓨褰撳墠鐨勮褰曘 CActiveRecord
saveAttributes() 淇濆瓨鎵閫夌殑灞炴у垪琛ㄣ CActiveRecord
saveCounters() 淇濆瓨涓涓垨澶氬綋鍓岮R瀵硅薄鍒拌鏁板櫒銆 CActiveRecord
scopes() 杩斿洖鐢虫槑鐨勫懡鍚嶈寖鍥淬 CActiveRecord
setAttribute() 璁剧疆鍛藉悕鐨勫睘鎬у笺 CActiveRecord
setAttributes() Sets the attribute values in a massive way. CModel
setDbCriteria() 涓哄綋鍓嶆ā鍨嬭缃煡璇㈡潯浠. CActiveRecord
setIsNewRecord() 璁剧疆璁板綍鏄惁鏄柊鐨勩 CActiveRecord
setOldPrimaryKey() 璁剧疆鏃х殑涓婚敭鍊笺 CActiveRecord
setPrimaryKey() 璁剧疆涓婚敭鍊笺 CActiveRecord
setScenario() Sets the scenario for the model. CModel
setTableAlias() 璁剧疆琛ㄥ湪鏌ヨ涓娇鐢ㄧ殑鍒悕銆 CActiveRecord
tableName() 杩斿洖鍏宠仈鐨勬暟鎹簱琛ㄧ殑鍚嶇О銆 CActiveRecord
together() 璁剧疆CDbCriteria::together灞炴т负true銆 CActiveRecord
unsetAttributes() Sets the attributes to be null. CModel
update() 鏇存柊姝ゆ椿鍔ㄨ褰曟墍琛ㄧず鐨勮銆 CActiveRecord
updateAll() 鏇存柊浣跨敤鎸囧畾鏉′欢鐨勮褰曘 CActiveRecord
updateByPk() 鏇存柊鎸囧畾涓婚敭璁板綍鐨勮銆 CActiveRecord
updateCounters() 鏇存柊鐨勪竴涓垨澶氫釜璁℃暟鍣ㄣ CActiveRecord
validate() Performs the validation. CModel
with() 鎸囧畾鐩稿叧瀵硅薄搴斾竴璧疯浇鍏ャ CActiveRecord

鍙椾繚鎶ゆ柟娉

闅愯棌缁ф壙鏂规硶

鏂规硶鎻忚堪瀹氫箟鍦
afterConstruct() This method is invoked after a model instance is created by new operator. CModel
afterDelete() 鍒犻櫎璁板綍涔嬪悗璋冪敤姝ゆ柟娉曘 CActiveRecord
afterFind() 姣忎釜璁板綍鐢 find 鏂规硶瀹炰緥鍖栧悗锛屽皢璋冪敤姝ゆ柟娉曘 CActiveRecord
afterSave() 璁板綍琚垚鍔熶繚瀛樺悗锛岃皟鐢ㄦ鏂规硶銆 CActiveRecord
afterValidate() This method is invoked after validation ends. CModel
beforeDelete() 鍦ㄥ垹闄よ褰曚箣鍓嶈皟鐢ㄦ鏂规硶銆 CActiveRecord
beforeFind() AR finder鎵ц鏌ユ壘璋冪敤涔嬪墠锛屽皢寮曞彂姝や簨浠躲 CActiveRecord
beforeSave() 淇濆瓨璁板綍涔嬪墠锛岃皟鐢ㄨ繖涓柟娉曪紙楠岃瘉鍚庯紝濡傛灉鏈夌殑璇濓級銆 CActiveRecord
beforeValidate() This method is invoked before validation starts. CModel
instantiate() 鍒涘缓娲诲姩璁板綍瀹炰緥銆 CActiveRecord
query() 鎵ц瀹為檯鐨勬暟鎹簱鏌ヨ鍜屽~鍏匒R瀵硅薄鐨勬煡璇㈢粨鏋溿 CActiveRecord

浜嬩欢

闅愯棌缁ф壙浜嬩欢

浜嬩欢鎻忚堪瀹氫箟鍦
onBeforeSave 淇濆瓨璁板綍涔嬪墠锛屽皢寮曞彂姝や簨浠躲 CActiveRecord
onAfterSave 淇濆瓨璁板綍涔嬪悗锛屽皢寮曞彂姝や簨浠躲 CActiveRecord
onBeforeDelete 鍦ㄥ垹闄よ褰曚箣鍓嶏紝灏嗗紩鍙戞浜嬩欢銆 CActiveRecord
onAfterDelete 鍦ㄥ垹闄よ褰曚箣鍚庯紝灏嗗紩鍙戞浜嬩欢銆 CActiveRecord
onBeforeFind AR finder鎵ц鏌ユ壘璋冪敤涔嬪墠锛屽皢寮曞彂姝や簨浠躲 CActiveRecord
onAfterFind 寮曞彂姝や簨浠惰褰曞悗鎵惧埌鏂规硶鐨勫疄渚嬨 CActiveRecord
onAfterConstruct This event is raised after the model instance is created by new operator. CModel
onBeforeValidate This event is raised before the validation is performed. CModel
onAfterValidate This event is raised after the validation is performed. CModel
onUnsafeAttribute This method is invoked when an unsafe attribute is being massively assigned. CModel

灞炴ц缁

attributes 灞炴
public array getAttributes(mixed $names=true)
public void setAttributes(array $values, boolean $safeOnly=true)

杩斿洖鎵鏈夊垪鐨勫睘鎬у笺 娉ㄦ剰锛屼笉杩斿洖鐩稿叧鐨勫璞°

commandBuilder 灞炴 鍙

杩斿洖姝R鐨勫懡浠ょ敓鎴愬櫒銆

db 灞炴
public static CDbConnection $db;

鎵鏈夋椿鍔ㄨ褰曠被鐨勯粯璁ゆ暟鎹簱杩炴帴銆 榛樿鎯呭喌涓嬶紝杩欐槸'db'搴旂敤绋嬪簭缁勪欢锛

鍙傝

dbConnection 灞炴 鍙

杩斿洖娲诲姩璁板綍鎵浣跨敤鐨勬暟鎹簱杩炴帴銆 榛樿鎯呭喌涓嬶紝"db"搴旂敤绋嬪簭缁勪欢鐢ㄤ綔鏁版嵁搴撹繛鎺ャ 濡傛灉鎮ㄨ浣跨敤涓涓笉鍚岀殑鏁版嵁搴撹繛鎺ワ紝鎮ㄥ彲浠ラ噸鍐欐鏂规硶銆

dbCriteria 灞炴
public CDbCriteria getDbCriteria(boolean $createIfNull=true)
public void setDbCriteria(CDbCriteria $criteria)

杩斿洖鍜岃繖涓ā鍨嬬浉鍏崇殑鏌ヨ鏉′欢銆

isNewRecord 灞炴
public boolean getIsNewRecord()
public void setIsNewRecord(boolean $value)

杩斿洖褰撳墠璁板綍鏄惁鏄柊鐨勩

metaData 灞炴 鍙

杩斿洖杩欎釜AR鐨勫厓鏁版嵁銆

oldPrimaryKey 灞炴 锛堝彲鐢ㄨ嚜 v1.1.0锛
public mixed getOldPrimaryKey()
public void setOldPrimaryKey(mixed $value)

杩斿洖鏃х殑涓婚敭鍊笺 杩欐寚鐨勬槸涓婚敭鍊煎凡濉厖鍒拌褰曞悗锛 鎵ц鏌ユ壘鏂规硶 (渚嬪锛 find()锛宖indAll())锛 鍗充娇涓诲叧閿睘鎬ч兘浼氳鎵嬪姩鍒嗛厤涓涓笉鍚岀殑鍊硷紝鍊间繚鎸佷笉鍙樸

primaryKey 灞炴
public mixed getPrimaryKey()
public void setPrimaryKey(mixed $value)

杩斿洖涓婚敭鍊笺

tableAlias 灞炴 锛堝彲鐢ㄨ嚜 v1.1.1锛
public string getTableAlias(boolean $quote=false, boolean $checkScopes=true)
public void setTableAlias(string $alias)

杩斿洖鐢 find 鏂规硶浣跨敤琛ㄧ殑鍒悕銆 鍦ㄥ叧绯绘煡璇紝鏍规嵁瀵瑰簲鍏崇郴鐨勫0鏄庯紝 杩斿洖鐨勮〃鐨勫埆鍚嶅彲鑳戒細鏈夋墍涓嶅悓銆 姝ゅ锛岀敱setTableAlias鍙互鐢卞簲鐢ㄧ殑鑼冨洿瑕嗙洊銆

tableSchema 灞炴 鍙

杩斿洖琛ㄧ殑鍏冩暟鎹紝杩欏睘浜嶢R绫汇

鏂规硶璇︾粏

__call() 鏂规硶
public mixed __call(string $name, array $parameters)
$name string 鏂规硶鍚
$parameters array 鏂规硶鍙傛暟
{return} mixed 姝ゆ柟娉曡繑鍥炲
婧愮爜锛 framework/db/ar/CActiveRecord.php#209 (鏄剧ず)
public function __call($name,$parameters)
{
    if(isset(
$this->getMetaData()->relations[$name]))
    {
        if(empty(
$parameters))
            return 
$this->getRelated($name,false);
        else
            return 
$this->getRelated($name,false,$parameters[0]);
    }

    
$scopes=$this->scopes();
    if(isset(
$scopes[$name]))
    {
        
$this->getDbCriteria()->mergeWith($scopes[$name]);
        return 
$this;
    }

    return 
parent::__call($name,$parameters);
}

鍥炶皟鐨勫懡鍚嶆柟娉曘 璇蜂笉瑕佽皟鐢ㄥ畠锛屽畠涓嶆槸绫荤殑鏂规硶銆 杩欐槸鎴戜滑閲嶅啓涓涓狿HP榄旀湳鏂规硶瀹炵幇浜嗚繖涓懡鍚嶈寖鍥寸殑鍔熻兘銆

__construct() 鏂规硶
public void __construct(string $scenario='insert')
$scenario string 鍦烘櫙鍚嶃傚弬瑙CModel::scenario鍏充簬杩欎釜鍙傛暟鐨勬洿澶氫俊鎭
婧愮爜锛 framework/db/ar/CActiveRecord.php#71 (鏄剧ず)
public function __construct($scenario='insert')
{
    if(
$scenario===null// internally used by populateRecord() and model()
        
return;

    
$this->setScenario($scenario);
    
$this->setIsNewRecord(true);
    
$this->_attributes=$this->getMetaData()->attributeDefaults;

    
$this->init();

    
$this->attachBehaviors($this->behaviors());
    
$this->afterConstruct();
}

鏋勯犲嚱鏁般

__get() 鏂规硶
public mixed __get(string $name)
$name string 灞炴у悕
{return} mixed 灞炴у
婧愮爜锛 framework/db/ar/CActiveRecord.php#133 (鏄剧ず)
public function __get($name)
{
    if(isset(
$this->_attributes[$name]))
        return 
$this->_attributes[$name];
    else if(isset(
$this->getMetaData()->columns[$name]))
        return 
null;
    else if(isset(
$this->_related[$name]))
        return 
$this->_related[$name];
    else if(isset(
$this->getMetaData()->relations[$name]))
        return 
$this->getRelated($name);
    else
        return 
parent::__get($name);
}

PHP getter 榄旀湳鏂规硶銆 閲嶅啓姝ゆ柟娉曪紝浠ヤ究AR灞炴ц兘鍍忓睘鎬ч偅鏍疯闂

鍙傝

__isset() 鏂规硶
public boolean __isset(string $name)
$name string 灞炴у悕鎴栦簨浠跺悕
{return} boolean 鏄惁灞炴у间负null
婧愮爜锛 framework/db/ar/CActiveRecord.php#171 (鏄剧ず)
public function __isset($name)
{
    if(isset(
$this->_attributes[$name]))
        return 
true;
    else if(isset(
$this->getMetaData()->columns[$name]))
        return 
false;
    else if(isset(
$this->_related[$name]))
        return 
true;
    else if(isset(
$this->getMetaData()->relations[$name]))
        return 
$this->getRelated($name)!==null;
    else
        return 
parent::__isset($name);
}

妫娴嬩竴涓睘鎬у兼槸鍚︿负null銆 閫氳繃妫娴嬶紝濡傛灉鍛戒护灞炴т负绌烘垨涓嶅瓨鍦紝 姝ゆ柟娉曢噸鍐欑埗绫汇

__set() 鏂规硶
public void __set(string $name, mixed $value)
$name string 灞炴у悕
$value mixed 灞炴у
婧愮爜锛 framework/db/ar/CActiveRecord.php#153 (鏄剧ず)
public function __set($name,$value)
{
    if(
$this->setAttribute($name,$value)===false)
    {
        if(isset(
$this->getMetaData()->relations[$name]))
            
$this->_related[$name]=$value;
        else
            
parent::__set($name,$value);
    }
}

PHP setter 榄旀湳鏂规硶銆 閲嶅啓姝ゆ柟娉曪紝浠ヤ究AR灞炴ц兘鍍忓睘鎬ч偅鏍疯闂

__sleep() 鏂规硶
public array __sleep()
{return} array
婧愮爜锛 framework/db/ar/CActiveRecord.php#120 (鏄剧ず)
public function __sleep()
{
    
$this->_md=null;
    return 
array_keys((array)$this);
}

PHP sleep 榄旀湳鏂规硶銆 姝ゆ柟娉曠‘淇濇ā鍨嬪厓鏁版嵁寮曠敤琚缃负 null銆

__unset() 鏂规硶
public void __unset(string $name)
$name string 灞炴у悕鎴栦簨浠跺悕
婧愮爜锛 framework/db/ar/CActiveRecord.php#191 (鏄剧ず)
public function __unset($name)
{
    if(isset(
$this->getMetaData()->columns[$name]))
        unset(
$this->_attributes[$name]);
    else if(isset(
$this->getMetaData()->relations[$name]))
        unset(
$this->_related[$name]);
    else
        
parent::__unset($name);
}

妫鏌ュ睘鎬у兼槸鍚︿负绌恒 閫氳繃妫娴嬶紝濡傛灉鍛戒护灞炴т负绌烘垨涓嶅瓨鍦紝 姝ゆ柟娉曢噸鍐欑埗绫汇

addRelatedRecord() 鏂规硶
public void addRelatedRecord(string $name, mixed $record, mixed $index)
$name string 灞炴у悕绉
$record mixed 鐩稿叧鐨勮褰
$index mixed 鐩稿叧瀵硅薄闆嗗悎涓殑绱㈠紩鍊笺 濡傛灉true锛岃繖鎰忓懗鐫浣跨敤浠庨浂寮濮嬬殑鏁存暟绱㈠紩銆 濡傛灉false锛屽畠鎰忓懗鐫HAS_ONE鎴朆ELONGS_TO瀵硅薄鍜岀储寮曚笉闇瑕併
婧愮爜锛 framework/db/ar/CActiveRecord.php#708 (鏄剧ず)
public function addRelatedRecord($name,$record,$index)
{
    if(
$index!==false)
    {
        if(!isset(
$this->_related[$name]))
            
$this->_related[$name]=array();
        if(
$record instanceof CActiveRecord)
        {
            if(
$index===true)
                
$this->_related[$name][]=$record;
            else
                
$this->_related[$name][$index]=$record;
        }
    }
    else if(!isset(
$this->_related[$name]))
        
$this->_related[$name]=$record;
}

涓嶈皟鐢ㄦ鏂规硶銆傛鏂规硶鐢ㄤ簬鍐呴儴CActiveFinder鏉ュ~鍏呯浉鍏崇殑瀵硅薄銆 姝ゆ柟娉曟坊鍔犲埌姝よ褰曠殑鐩稿叧鐨勫璞°

afterDelete() 鏂规硶
protected void afterDelete()
婧愮爜锛 framework/db/ar/CActiveRecord.php#933 (鏄剧ず)
protected function afterDelete()
{
    if(
$this->hasEventHandler('onAfterDelete'))
        
$this->onAfterDelete(new CEvent($this));
}

鍒犻櫎璁板綍涔嬪悗璋冪敤姝ゆ柟娉曘 杩欎釜榛樿鎵ц寮曞彂onAfterDelete浜嬩欢銆 鎮ㄥ彲浠ラ噸鍐欐鏂规硶锛屽湪璁板綍琚垹闄ゅ悗鍋氬鐞嗐 璇风‘淇濇偍璋冪敤鐖跺疄渚嬶紝浠ヤ究姝g‘鍦板紩鍙戣浜嬩欢銆

afterFind() 鏂规硶
protected void afterFind()
婧愮爜锛 framework/db/ar/CActiveRecord.php#968 (鏄剧ず)
protected function afterFind()
{
    if(
$this->hasEventHandler('onAfterFind'))
        
$this->onAfterFind(new CEvent($this));
}

姣忎釜璁板綍鐢 find 鏂规硶瀹炰緥鍖栧悗锛屽皢璋冪敤姝ゆ柟娉曘 杩欎釜榛樿鎵ц寮曞彂onAfterFind浜嬩欢銆 浣犲彲浠ラ噸鍐欒繖涓柟娉曪紝 鍋氬鐞嗗悗姣忎釜鏂版煡鎵剧殑璁板綍瀹炰緥銆 璇风‘淇濇偍璋冪敤鐖跺疄渚嬶紝浠ヤ究姝g‘鍦板紩鍙戣浜嬩欢銆

afterFindInternal() 鏂规硶
public void afterFindInternal()
婧愮爜锛 framework/db/ar/CActiveRecord.php#987 (鏄剧ず)
public function afterFindInternal()
{
    
$this->afterFind();
}

璋冪敤afterFind銆 杩欎釜鏂规硶鍐呴儴浣跨敤銆

afterSave() 鏂规硶
protected void afterSave()
婧愮爜锛 framework/db/ar/CActiveRecord.php#902 (鏄剧ず)
protected function afterSave()
{
    if(
$this->hasEventHandler('onAfterSave'))
        
$this->onAfterSave(new CEvent($this));
}

璁板綍琚垚鍔熶繚瀛樺悗锛岃皟鐢ㄦ鏂规硶銆 杩欎釜榛樿鎵ц寮曞彂onAfterSave浜嬩欢銆 鎮ㄥ彲閲嶅啓姝ゆ柟娉曪紝浠ヨ褰曚繚瀛樺悗鍋氬悗澶勭悊銆 璇风‘淇濇偍璋冪敤鐖跺疄渚嬶紝浠ヤ究姝g‘鍦板紩鍙戣浜嬩欢銆

applyScopes() 鏂规硶
public void applyScopes(CDbCriteria &$criteria)
$criteria CDbCriteria 鏌ヨ鏉′欢銆傞氳繃鍚堝苟dbCriteria鍙慨鏀规鍙傛暟銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1302 (鏄剧ず)
public function applyScopes(&$criteria)
{
    if(!empty(
$criteria->scopes))
    {
        
$scs=$this->scopes();
        
$c=$this->getDbCriteria();
        foreach((array)
$criteria->scopes as $k=>$v)
        {
            if(
is_integer($k))
            {
                if(
is_string($v))
                {
                    if(isset(
$scs[$v]))
                    {
                        
$c->mergeWith($scs[$v],true);
                        continue;
                    }
                    
$scope=$v;
                    
$params=array();
                }
                else if(
is_array($v))
                {
                    
$scope=key($v);
                    
$params=current($v);
                }
            }
            else if(
is_string($k))
            {
                
$scope=$k;
                
$params=$v;
            }

            
call_user_func_array(array($this,$scope),(array)$params);
        }
    }

    if(isset(
$c) || ($c=$this->getDbCriteria(false))!==null)
    {
        
$c->mergeWith($criteria);
        
$criteria=$c;
        
$this->_c=null;
    }
}

閫傜敤浜庣粰瀹氭潯浠剁殑鏌ヨ鑼冨洿銆 杩欑鏂规硶鍚堝苟dbCriteria涓庣粰瀹氱殑鏉′欢鍙傛暟銆 瀹冨皢閲嶇疆dbCriteria涓簄ull銆

attributeNames() 鏂规硶
public array attributeNames()
{return} array 灞炴у悕绉板垪琛
婧愮爜锛 framework/db/ar/CActiveRecord.php#563 (鏄剧ず)
public function attributeNames()
{
    return 
array_keys($this->getMetaData()->columns);
}

杩斿洖妯″瀷鐨勬墍鏈夊睘鎬у悕绉扮殑鍒楄〃銆 杩欏皢杩斿洖AR绫讳笌姝ょ浉鍏宠仈鐨勬墍鏈夎〃鐨勫垪鍚嶃

beforeDelete() 鏂规硶
protected boolean beforeDelete()
{return} boolean 鏄惁搴斿垹闄よ褰曘傞粯璁ゅ间负true銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#915 (鏄剧ず)
protected function beforeDelete()
{
    if(
$this->hasEventHandler('onBeforeDelete'))
    {
        
$event=new CModelEvent($this);
        
$this->onBeforeDelete($event);
        return 
$event->isValid;
    }
    else
        return 
true;
}

鍦ㄥ垹闄よ褰曚箣鍓嶈皟鐢ㄦ鏂规硶銆 杩欎釜榛樿鎵ц寮曞彂onBeforeDelete浜嬩欢銆 鎮ㄥ彲浠ラ噸鍐欐鏂规硶锛屼互鍋氫负璁板綍鍒犻櫎浠讳綍鍑嗗宸ヤ綔銆 璇风‘淇濇偍璋冪敤鐖跺疄渚嬶紝浠ヤ究姝g‘鍦板紩鍙戣浜嬩欢銆

beforeFind() 鏂规硶
protected void beforeFind()
婧愮爜锛 framework/db/ar/CActiveRecord.php#951 (鏄剧ず)
protected function beforeFind()
{
    if(
$this->hasEventHandler('onBeforeFind'))
    {
        
$event=new CModelEvent($this);
        
// for backward compatibility
        
$event->criteria=func_num_args()>func_get_arg(0) : null;
        
$this->onBeforeFind($event);
    }
}

AR finder鎵ц鏌ユ壘璋冪敤涔嬪墠锛屽皢寮曞彂姝や簨浠躲 鏌ユ壘璋冪敤鍖呮嫭findfindAllfindByPkfindAllByPkfindByAttributesfindAllByAttributes銆 杩欎釜榛樿鎵ц寮曞彂onBeforeFind浜嬩欢銆 濡傛灉閲嶅啓姝ゆ柟娉曪紝 璇风‘淇濇偍璋冪敤鐖跺疄渚嬶紝浠ヤ究姝g‘鍦板紩鍙戣浜嬩欢銆

浠1.1.5鐗堟湰寮濮嬶紝 杩欑鏂规硶鍙О涓轰竴涓殣钘忕殑鍙傛暟CDbCriteria琛ㄧず褰撳墠鏌ヨ鏉′欢浼犻掑埌涓涓狝R鏂规硶銆

beforeFindInternal() 鏂规硶
public void beforeFindInternal()
婧愮爜锛 framework/db/ar/CActiveRecord.php#978 (鏄剧ず)
public function beforeFindInternal()
{
    
$this->beforeFind();
}

璋冪敤beforeFind銆 杩欎釜鏂规硶鍐呴儴浣跨敤銆

beforeSave() 鏂规硶
protected boolean beforeSave()
{return} boolean 鏄惁搴旇鎵ц鍙湪锛岄粯璁や负true銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#884 (鏄剧ず)
protected function beforeSave()
{
    if(
$this->hasEventHandler('onBeforeSave'))
    {
        
$event=new CModelEvent($this);
        
$this->onBeforeSave($event);
        return 
$event->isValid;
    }
    else
        return 
true;
}

淇濆瓨璁板綍涔嬪墠锛岃皟鐢ㄨ繖涓柟娉曪紙楠岃瘉鍚庯紝濡傛灉鏈夌殑璇濓級銆 榛樿瀹炵幇寮曞彂onBeforeSave浜嬩欢銆 鎮ㄥ彲浠ラ噸鍐欐鏂规硶鍋氫换浣曡褰曚繚瀛樼殑鍑嗗宸ヤ綔銆 浣跨敤isNewRecord 浠ョ‘璁ゆ槸鍚︽槸鎻掑叆鎴栦繚瀛樿褰曘 璇风‘淇濇偍璋冪敤鐖跺疄渚嬶紝浠ヤ究姝g‘鍦板紩鍙戣浜嬩欢銆

cache() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.7锛
public CActiveRecord cache(integer $duration, CCacheDependency $dependency=NULL, integer $queryCount=1)
$duration integer 鏌ヨ缁撴灉鍙兘淇濇寔鍦ㄧ紦瀛樹腑鏈夋晥鐨勭鏁般 濡傛灉杩欐槸0锛岀紦瀛樺皢琚鐢ㄣ
$dependency CCacheDependency 淇濆瓨鏌ヨ缁撴灉鍒扮紦瀛樻椂浣跨敤鐨勪緷璧栧叧绯汇
$queryCount integer 鍦ㄨ皟鐢ㄦ鏂规硶鍚庯紝闇瑕佺紦瀛樼殑SQL鏌ヨ鐨勬暟鐩 榛樿鍊间负 1锛岃繖鎰忓懗鐫涓嬩竴涓猄QL鏌ヨ灏嗚缂撳瓨銆
{return} CActiveRecord AR瀹炰緥鏈韩銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#109 (鏄剧ず)
public function cache($duration$dependency=null$queryCount=1)
{
    
$this->getDbConnection()->cache($duration$dependency$queryCount);
    return 
$this;
}

璁剧疆鍏充簬鏌ヨ缂撳瓨鐨勫弬鏁. 杩欐槸CDbConnection::cache()鐨勪竴绉嶅揩鎹锋柟娉曘 瀹冩敼鍙樻煡璇㈢紦瀛樼殑dbConnection瀹炰緥鍙傛暟銆

count() 鏂规硶
public string count(mixed $condition='', array $params=array ( ))
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} string 婊¤冻鎸囧畾鐨勬煡璇㈡潯浠剁殑琛屾暟銆傛敞锛氱被鍨嬫槸瀛楃涓蹭繚鎸佹渶澶х簿搴︺
婧愮爜锛 framework/db/ar/CActiveRecord.php#1528 (鏄剧ず)
public function count($condition='',$params=array())
{
    
Yii::trace(get_class($this).'.count()','system.db.ar.CActiveRecord');
    
$builder=$this->getCommandBuilder();
    
$criteria=$builder->createCriteria($condition,$params);
    
$this->applyScopes($criteria);

    if(empty(
$criteria->with))
        return 
$builder->createCountCommand($this->getTableSchema(),$criteria)->queryScalar();
    else
    {
        
$finder=new CActiveFinder($this,$criteria->with);
        return 
$finder->count($criteria);
    }
}

鏌ユ壘婊¤冻鎸囧畾鏌ヨ鏉′欢鐨勮鏁般 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

countByAttributes() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.4锛
public string countByAttributes(array $attributes, mixed $condition='', array $params=array ( ))
$attributes array 鍒楄〃涓殑灞炴у硷紙灞炴у悕绱㈠紩锛夋椿鍔ㄨ褰曠浉鍖归厤銆 灞炴у煎彲浠ユ槸涓涓暟缁勶紝鐢ㄤ簬鐢熸垚鐨勬潯浠躲
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} string 婊¤冻鎸囧畾鐨勬煡璇㈡潯浠剁殑琛屾暟銆傛敞锛氱被鍨嬫槸瀛楃涓蹭繚鎸佹渶澶х簿搴︺
婧愮爜锛 framework/db/ar/CActiveRecord.php#1554 (鏄剧ず)
public function countByAttributes($attributes,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.countByAttributes()','system.db.ar.CActiveRecord');
    
$prefix=$this->getTableAlias(true).'.';
    
$builder=$this->getCommandBuilder();
    
$criteria=$builder->createColumnCriteria($this->getTableSchema(),$attributes,$condition,$params,$prefix);
    
$this->applyScopes($criteria);

    if(empty(
$criteria->with))
        return 
$builder->createCountCommand($this->getTableSchema(),$criteria)->queryScalar();
    else
    {
        
$finder=new CActiveFinder($this,$criteria->with);
        return 
$finder->count($criteria);
    }
}

鏌ユ壘鍏锋湁鎸囧畾鐨勫睘鎬у肩殑琛屾暟銆 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

countBySql() 鏂规硶
public string countBySql(string $sql, array $params=array ( ))
$sql string SQL璇彞
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} string 婊¤冻鎸囧畾鐨勬煡璇㈡潯浠剁殑琛屾暟銆傛敞锛氱被鍨嬫槸瀛楃涓蹭繚鎸佹渶澶х簿搴︺
婧愮爜锛 framework/db/ar/CActiveRecord.php#1579 (鏄剧ず)
public function countBySql($sql,$params=array())
{
    
Yii::trace(get_class($this).'.countBySql()','system.db.ar.CActiveRecord');
    return 
$this->getCommandBuilder()->createSqlCommand($sql,$params)->queryScalar();
}

鏌ユ壘鎸囧畾SQL璇彞褰卞搷鐨勮鏁般 杩欑浉褰撲簬璋冪敤CDbCommand::queryScalar锛 浠ユ寚瀹氱殑SQL澹版槑鍜屽弬鏁般

defaultScope() 鏂规硶
public array defaultScope()
{return} array 鏌ヨ鏉′欢銆 杩欏皢浣滀负CDbCriteria鍙傛暟鐨勬瀯閫犳柟娉曘
婧愮爜锛 framework/db/ar/CActiveRecord.php#339 (鏄剧ず)
public function defaultScope()
{
    return array();
}

杩斿洖榛樿鐨勫懡鍚嶈寖鍥达紝搴旈殣鍚繖绉嶆ā寮忛傜敤浜庢墍鏈夋煡璇€ 娉ㄦ剰锛岄粯璁ょ殑鑼冨洿鍙傜敤浜嶴ELECT鏌ヨ銆傚拷瑙嗗INSERT锛孶PDATE鍜孌ELETE鏌ヨ銆 榛樿瀹炵幇鍙繑鍥炰竴涓┖鏁扮粍銆 濡傛灉妯″瀷闇瑕佷竴浜涢粯璁ょ殑鏍囧噯锛堝鍙湁娲诲姩璁板綍锛屽綋杩斿洖锛夋煡璇紝浣犲彲浠ラ噸鍐欐鏂规硶銆

delete() 鏂规硶
public boolean delete()
{return} boolean 鏄惁鍒犻櫎鎴愬姛銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1152 (鏄剧ず)
public function delete()
{
    if(!
$this->getIsNewRecord())
    {
        
Yii::trace(get_class($this).'.delete()','system.db.ar.CActiveRecord');
        if(
$this->beforeDelete())
        {
            
$result=$this->deleteByPk($this->getPrimaryKey())>0;
            
$this->afterDelete();
            return 
$result;
        }
        else
            return 
false;
    }
    else
        throw new 
CDbException(Yii::t('yii','The active record cannot be deleted because it is new.'));
}

鍒犻櫎瀵瑰簲浜庢娲诲姩璁板綍鐨勮銆

deleteAll() 鏂规硶
public integer deleteAll(mixed $condition='', array $params=array ( ))
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} integer 鍒犻櫎鐨勮鏁
婧愮爜锛 framework/db/ar/CActiveRecord.php#1745 (鏄剧ず)
public function deleteAll($condition='',$params=array())
{
    
Yii::trace(get_class($this).'.deleteAll()','system.db.ar.CActiveRecord');
    
$builder=$this->getCommandBuilder();
    
$criteria=$builder->createCriteria($condition,$params);
    
$command=$builder->createDeleteCommand($this->getTableSchema(),$criteria);
    return 
$command->execute();
}

鍒犻櫎鎸囧畾鏉′欢鐨勮銆 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

deleteAllByAttributes() 鏂规硶
public integer deleteAllByAttributes(array $attributes, mixed $condition='', array $params=array ( ))
$attributes array 鍒楄〃涓殑灞炴у硷紙灞炴у悕绱㈠紩锛夋椿鍔ㄨ褰曠浉鍖归厤銆 灞炴у煎彲浠ユ槸涓涓暟缁勶紝鐢ㄤ簬鐢熸垚鐨勬潯浠躲
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} integer 鎵ц褰卞搷鐨勮鏁般
婧愮爜锛 framework/db/ar/CActiveRecord.php#1763 (鏄剧ず)
public function deleteAllByAttributes($attributes,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.deleteAllByAttributes()','system.db.ar.CActiveRecord');
    
$builder=$this->getCommandBuilder();
    
$table=$this->getTableSchema();
    
$criteria=$builder->createColumnCriteria($table,$attributes,$condition,$params);
    
$command=$builder->createDeleteCommand($table,$criteria);
    return 
$command->execute();
}

鍒犻櫎鎸囧畾鐨勫睘鎬у肩浉鍖归厤鐨勮銆 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

deleteByPk() 鏂规硶
public integer deleteByPk(mixed $pk, mixed $condition='', array $params=array ( ))
$pk mixed 涓婚敭鍊笺傚澶氫釜涓婚敭浣跨敤鏁扮粍銆傚鍚堥敭锛屽浜庢瘡涓敭鐨勫煎繀椤绘槸涓涓暟缁勶紙鍒楀悕=>鍒楀硷級銆
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} integer 鍒犻櫎鐨勮鏁
婧愮爜锛 framework/db/ar/CActiveRecord.php#1729 (鏄剧ず)
public function deleteByPk($pk,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.deleteByPk()','system.db.ar.CActiveRecord');
    
$builder=$this->getCommandBuilder();
    
$criteria=$builder->createPkCriteria($this->getTableSchema(),$pk,$condition,$params);
    
$command=$builder->createDeleteCommand($this->getTableSchema(),$criteria);
    return 
$command->execute();
}

鍒犻櫎鎸囧畾涓婚敭鐨勮銆 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

equals() 鏂规硶
public boolean equals(CActiveRecord $record)
$record CActiveRecord 瑕佹瘮杈冪殑璁板綍
{return} boolean 涓や釜娲诲姩鐨勮褰曟槸鍚︽槸鎸囨暟鎹簱琛ㄤ腑鐨勫悓涓琛屻
婧愮爜锛 framework/db/ar/CActiveRecord.php#1200 (鏄剧ず)
public function equals($record)
{
    return 
$this->tableName()===$record->tableName() && $this->getPrimaryKey()===$record->getPrimaryKey();
}

褰撳墠娲诲姩璁板綍涓庡彟涓涓瘮杈冦 閫氳繃姣旇緝琛ㄥ悕鍜屼袱涓椿鍔ㄨ褰曠殑涓婚敭鍊兼潵浣滄瘮杈冦

exists() 鏂规硶
public boolean exists(mixed $condition='', array $params=array ( ))
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} boolean 鏄惁婊¤冻鎸囧畾鏉′欢鐨勮銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1592 (鏄剧ず)
public function exists($condition='',$params=array())
{
    
Yii::trace(get_class($this).'.exists()','system.db.ar.CActiveRecord');
    
$builder=$this->getCommandBuilder();
    
$criteria=$builder->createCriteria($condition,$params);
    
$table=$this->getTableSchema();
    
$criteria->select='1';
    
$criteria->limit=1;
    
$this->applyScopes($criteria);

    if(empty(
$criteria->with))
        return 
$builder->createFindCommand($table,$criteria)->queryRow()!==false;
    else
    {
        
$criteria->select='*';
        
$finder=new CActiveFinder($this,$criteria->with);
        return 
$finder->count($criteria)>0;
    }
}

妫鏌ユ槸鍚︽弧瓒虫寚瀹氭潯浠剁殑琛屻 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

find() 鏂规硶
public CActiveRecord find(mixed $condition='', array $params=array ( ))
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐 濡傛灉涓涓瓧绗︿覆锛屽畠琚綔涓烘煡璇㈡潯浠 锛圵HERE 瀛愬彞锛 锛 濡傛灉涓涓暟缁勶紝瀹冭瑙嗕负鏋勫缓CDbCriteria瀵硅薄鍒濆鍊; 鍚﹀垯锛屽畠搴旇鏄CDbCriteria瀵硅薄鐨勪竴涓疄渚嬨
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁般 杩欎粎浠呮槸绗竴涓弬鏁版槸涓涓瓧绗︿覆锛堟煡璇㈡潯浠讹級鏃朵娇鐢ㄣ 鍦ㄥ叾浠栨儏鍐典笅锛岃浣跨敤CDbCriteria::params璁剧疆鍙傛暟銆
{return} CActiveRecord 鎵惧埌鐨勮褰曘傚鏋滄病鎵惧埌浠讳綍璁板綍锛屽垯涓 null銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1388 (鏄剧ず)
public function find($condition='',$params=array())
{
    
Yii::trace(get_class($this).'.find()','system.db.ar.CActiveRecord');
    
$criteria=$this->getCommandBuilder()->createCriteria($condition,$params);
    return 
$this->query($criteria);
}

鏌ユ壘鎸囧畾鏉′欢鐨勫崟涓椿鍔ㄨ褰曘

findAll() 鏂规硶
public array findAll(mixed $condition='', array $params=array ( ))
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁般
{return} array 婊¤冻鎸囧畾鏉′欢鐨勬椿鍔ㄨ褰曞垪琛紝濡傛灉娌℃湁鎵惧埌灏嗚繑鍥炰竴涓┖鐨勬暟缁勩
婧愮爜锛 framework/db/ar/CActiveRecord.php#1402 (鏄剧ず)
public function findAll($condition='',$params=array())
{
    
Yii::trace(get_class($this).'.findAll()','system.db.ar.CActiveRecord');
    
$criteria=$this->getCommandBuilder()->createCriteria($condition,$params);
    return 
$this->query($criteria,true);
}

鏌ユ壘婊¤冻鎸囧畾鏉′欢鐨勬墍鏈夋椿鍔ㄨ褰曘 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

findAllByAttributes() 鏂规硶
public array findAllByAttributes(array $attributes, mixed $condition='', array $params=array ( ))
$attributes array 鍒楄〃涓殑灞炴у硷紙灞炴у悕绱㈠紩锛夋椿鍔ㄨ褰曠浉鍖归厤銆 灞炴у煎彲浠ユ槸涓涓暟缁勫皢琚敤鏉ョ敓鎴愪竴涓潯浠躲
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁般
{return} array 鎵惧埌鐨勮褰曘傚鏋滄病鏈夋壘鍒拌繑鍥炰竴涓┖鏁扮粍銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1467 (鏄剧ず)
public function findAllByAttributes($attributes,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.findAllByAttributes()','system.db.ar.CActiveRecord');
    
$prefix=$this->getTableAlias(true).'.';
    
$criteria=$this->getCommandBuilder()->createColumnCriteria($this->getTableSchema(),$attributes,$condition,$params,$prefix);
    return 
$this->query($criteria,true);
}

鏌ユ壘鍏锋湁鎸囧畾灞炴у肩殑鎵鏈夋椿鍔ㄨ褰曘 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

findAllByPk() 鏂规硶
public array findAllByPk(mixed $pk, mixed $condition='', array $params=array ( ))
$pk mixed 涓婚敭鍊笺傚澶氫釜涓婚敭浣跨敤鏁扮粍銆傚鍚堥敭锛屽浜庢瘡涓敭鐨勫煎繀椤绘槸涓涓暟缁勶紙鍒楀悕=>鍒楀硷級銆
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁般
{return} array 鎵惧埌鐨勮褰曘傚鏋滄病鏈夋壘鍒拌繑鍥炰竴涓┖鏁扮粍銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1433 (鏄剧ず)
public function findAllByPk($pk,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.findAllByPk()','system.db.ar.CActiveRecord');
    
$prefix=$this->getTableAlias(true).'.';
    
$criteria=$this->getCommandBuilder()->createPkCriteria($this->getTableSchema(),$pk,$condition,$params,$prefix);
    return 
$this->query($criteria,true);
}

鏌ユ壘鎸囧畾涓婚敭鐨勬墍鏈夋椿鍔ㄨ褰曘 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

findAllBySql() 鏂规硶
public array findAllBySql(string $sql, array $params=array ( ))
$sql string SQL璇彞
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} array 鎵惧埌鐨勮褰曘傚鏋滄病鎵惧埌浠讳綍璁板綍锛屽垯涓 null銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1504 (鏄剧ず)
public function findAllBySql($sql,$params=array())
{
    
Yii::trace(get_class($this).'.findAllBySql()','system.db.ar.CActiveRecord');
    
$this->beforeFind();
    if((
$criteria=$this->getDbCriteria(false))!==null && !empty($criteria->with))
    {
        
$this->_c=null;
        
$finder=new CActiveFinder($this,$criteria->with);
        return 
$finder->findAllBySql($sql,$params);
    }
    else
    {
        
$command=$this->getCommandBuilder()->createSqlCommand($sql,$params);
        return 
$this->populateRecords($command->queryAll());
    }
}

鏌ユ壘鎸囧畾SQL璇彞鐨勬墍鏈夋椿鍔ㄨ褰曘

findByAttributes() 鏂规硶
public CActiveRecord findByAttributes(array $attributes, mixed $condition='', array $params=array ( ))
$attributes array 鍒楄〃涓殑灞炴у硷紙灞炴у悕绱㈠紩锛夋椿鍔ㄨ褰曠浉鍖归厤銆 灞炴у煎彲浠ユ槸涓涓暟缁勫皢琚敤鏉ョ敓鎴愪竴涓潯浠躲
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁般
{return} CActiveRecord 鎵惧埌鐨勮褰曘傚鏋滄病鎵惧埌浠讳綍璁板綍锛屽垯涓 null銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1450 (鏄剧ず)
public function findByAttributes($attributes,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.findByAttributes()','system.db.ar.CActiveRecord');
    
$prefix=$this->getTableAlias(true).'.';
    
$criteria=$this->getCommandBuilder()->createColumnCriteria($this->getTableSchema(),$attributes,$condition,$params,$prefix);
    return 
$this->query($criteria);
}

鏌ユ壘鍏锋湁鎸囧畾灞炴у肩殑鍗曚釜娲诲姩璁板綍銆 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

findByPk() 鏂规硶
public CActiveRecord findByPk(mixed $pk, mixed $condition='', array $params=array ( ))
$pk mixed 涓婚敭鍊笺傚澶氫釜涓婚敭浣跨敤鏁扮粍銆傚鍚堥敭锛屽浜庢瘡涓敭鐨勫煎繀椤绘槸涓涓暟缁勶紙鍒楀悕=>鍒楀硷級銆
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁般
{return} CActiveRecord 鎵惧埌鐨勮褰曘傚鏋滄病鎵惧埌浠讳綍璁板綍锛屽垯涓 null銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1417 (鏄剧ず)
public function findByPk($pk,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.findByPk()','system.db.ar.CActiveRecord');
    
$prefix=$this->getTableAlias(true).'.';
    
$criteria=$this->getCommandBuilder()->createPkCriteria($this->getTableSchema(),$pk,$condition,$params,$prefix);
    return 
$this->query($criteria);
}

鏌ユ壘鎸囧畾涓婚敭鐨勫崟涓娲诲姩璁板綍銆 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

findBySql() 鏂规硶
public CActiveRecord findBySql(string $sql, array $params=array ( ))
$sql string SQL璇彞
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} CActiveRecord 鎵惧埌鐨勮褰曘傚鏋滄病鎵惧埌浠讳綍璁板綍锛屽垯涓 null銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1481 (鏄剧ず)
public function findBySql($sql,$params=array())
{
    
Yii::trace(get_class($this).'.findBySql()','system.db.ar.CActiveRecord');
    
$this->beforeFind();
    if((
$criteria=$this->getDbCriteria(false))!==null && !empty($criteria->with))
    {
        
$this->_c=null;
        
$finder=new CActiveFinder($this,$criteria->with);
        return 
$finder->findBySql($sql,$params);
    }
    else
    {
        
$command=$this->getCommandBuilder()->createSqlCommand($sql,$params);
        return 
$this->populateRecord($command->queryRow());
    }
}

鏌ユ壘鎸囧畾SQL璇彞鐨勫崟涓椿鍔ㄨ褰曘

getActiveRelation() 鏂规硶
public CActiveRelation getActiveRelation(string $name)
$name string 鍏崇郴鍚嶇О
{return} CActiveRelation 涓烘AR绫诲0鏄庡懡鍚嶇殑鍏崇郴銆傚鏋滃叧绯讳笉瀛樺湪鍒欎负null銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#628 (鏄剧ず)
public function getActiveRelation($name)
{
    return isset(
$this->getMetaData()->relations[$name]) ? $this->getMetaData()->relations[$name] : null;
}

杩斿洖姝R绫诲0鏄庣殑鍛藉悕鍏崇郴銆

getAttribute() 鏂规硶
public mixed getAttribute(string $name)
$name string 灞炴у悕绉
{return} mixed 灞炴у笺傚鏋滃睘鎬ф湭璁剧疆鈥嬧嬫垨涓嶅瓨鍦ㄥ垯涓簄ull銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#672 (鏄剧ず)
public function getAttribute($name)
{
    if(
property_exists($this,$name))
        return 
$this->$name;
    else if(isset(
$this->_attributes[$name]))
        return 
$this->_attributes[$name];
}

杩斿洖鍛藉悕鐨勫睘鎬у笺 濡傛灉杩欐槸涓涓柊鐨勮褰曪紝璇ュ睘鎬ф湭璁剧疆涔嬪墠锛 灏嗚繑鍥炵殑鍒楃殑榛樿鍊笺 濡傛灉璇ヨ褰曟槸鏌ヨ鐨勭粨鏋滃苟涓嶅姞杞借灞炴ф椂锛 灏嗚繑鍥瀗ull銆 浣犱篃鍙互浣跨敤$this->AttributeName鏉ヨ幏寰楀睘鎬у笺

鍙傝

getAttributeLabel() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.4锛
public string getAttributeLabel(string $attribute)
$attribute string 灞炴у悕绉
{return} string 灞炴ф爣绛
婧愮爜锛 framework/db/ar/CActiveRecord.php#579 (鏄剧ず)
public function getAttributeLabel($attribute)
{
    
$labels=$this->attributeLabels();
    if(isset(
$labels[$attribute]))
        return 
$labels[$attribute];
    else if(
strpos($attribute,'.')!==false)
    {
        
$segs=explode('.',$attribute);
        
$name=array_pop($segs);
        
$model=$this;
        foreach(
$segs as $seg)
        {
            
$relations=$model->getMetaData()->relations;
            if(isset(
$relations[$seg]))
                
$model=CActiveRecord::model($relations[$seg]->className);
            else
                break;
        }
        return 
$model->getAttributeLabel($name);
    }
    else
        return 
$this->generateAttributeLabel($attribute);
}

杩斿洖鎸囧畾灞炴х殑鏂囨湰鏍囩銆 杩欎釜鏂规硶閲嶅啓鐖剁被锛 鏀寔杩斿洖鍏崇郴瀵硅薄涓畾涔夌殑鏍囩銆 鐗瑰埆娉ㄦ剰锛屽鏋滃睘鎬у悕绉版槸"post.author.name"鐨勫舰寮忥紝 閭d箞姝ゆ柟娉曚細浠"author"鍏崇郴"name"涓幏寰楀睘鎬ф爣绛俱

getAttributes() 鏂规硶
public array getAttributes(mixed $names=true)
$names mixed 灞炴х殑鍚嶇О锛屽叾鍊煎繀椤昏繑鍥炪 濡傛灉杩欐槸true锛堥粯璁わ級锛屽皢杩斿洖鎵鏈夊睘鎬э紝 鍖呮嫭閭d簺娌℃湁浠庢暟鎹簱鍔犺浇鐨勶紙杩欎簺灞炴у皢杩斿洖绌猴級銆 濡傛灉涓簄ull锛屽垯灏嗚繑鍥炴墍鏈夊睘鎬э紝鏁版嵁搴撴湭琚姞杞界殑闄ゅ銆
{return} array attribute values indexed by attribute names.
婧愮爜锛 framework/db/ar/CActiveRecord.php#735 (鏄剧ず)
public function getAttributes($names=true)
{
    
$attributes=$this->_attributes;
    foreach(
$this->getMetaData()->columns as $name=>$column)
    {
        if(
property_exists($this,$name))
            
$attributes[$name]=$this->$name;
        else if(
$names===true && !isset($attributes[$name]))
            
$attributes[$name]=null;
    }
    if(
is_array($names))
    {
        
$attrs=array();
        foreach(
$names as $name)
        {
            if(
property_exists($this,$name))
                
$attrs[$name]=$this->$name;
            else
                
$attrs[$name]=isset($attributes[$name])?$attributes[$name]:null;
        }
        return 
$attrs;
    }
    else
        return 
$attributes;
}

杩斿洖鎵鏈夊垪鐨勫睘鎬у笺 娉ㄦ剰锛屼笉杩斿洖鐩稿叧鐨勫璞°

getCommandBuilder() 鏂规硶
public CDbCommandBuilder getCommandBuilder()
{return} CDbCommandBuilder 杩欎釜鍛戒护鐢熸垚鍣ㄥ睘浜嶢R绫
婧愮爜锛 framework/db/ar/CActiveRecord.php#646 (鏄剧ず)
public function getCommandBuilder()
{
    return 
$this->getDbConnection()->getSchema()->getCommandBuilder();
}

杩斿洖姝R鐨勫懡浠ょ敓鎴愬櫒銆

getDbConnection() 鏂规硶
public CDbConnection getDbConnection()
{return} CDbConnection 娲诲姩璁板綍浣跨敤鐨勬暟鎹簱杩炴帴銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#609 (鏄剧ず)
public function getDbConnection()
{
    if(
self::$db!==null)
        return 
self::$db;
    else
    {
        
self::$db=Yii::app()->getDb();
        if(
self::$db instanceof CDbConnection)
            return 
self::$db;
        else
            throw new 
CDbException(Yii::t('yii','Active Record requires a "db" CDbConnection application component.'));
    }
}

杩斿洖娲诲姩璁板綍鎵浣跨敤鐨勬暟鎹簱杩炴帴銆 榛樿鎯呭喌涓嬶紝"db"搴旂敤绋嬪簭缁勪欢鐢ㄤ綔鏁版嵁搴撹繛鎺ャ 濡傛灉鎮ㄨ浣跨敤涓涓笉鍚岀殑鏁版嵁搴撹繛鎺ワ紝鎮ㄥ彲浠ラ噸鍐欐鏂规硶銆

getDbCriteria() 鏂规硶
public CDbCriteria getDbCriteria(boolean $createIfNull=true)
$createIfNull boolean 鏄惁鍒涘缓涓涓潯浠跺疄渚嬪鏋滃畠涓嶅瓨鍦ㄣ傞粯璁ゅ间负true銆
{return} CDbCriteria 鍜岃繖涓ā鍨嬬浉鍏崇殑鏌ヨ鏉′欢銆 杩欎釜鏉′欢涓昏琚 named scope浣跨敤锛 鐗瑰緛鏄Н绱笉鍚岀殑鏉′欢瑙勮寖銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#311 (鏄剧ず)
public function getDbCriteria($createIfNull=true)
{
    if(
$this->_c===null)
    {
        if((
$c=$this->defaultScope())!==array() || $createIfNull)
            
$this->_c=new CDbCriteria($c);
    }
    return 
$this->_c;
}

杩斿洖鍜岃繖涓ā鍨嬬浉鍏崇殑鏌ヨ鏉′欢銆

getIsNewRecord() 鏂规硶
public boolean getIsNewRecord()
{return} boolean 璇ヨ褰曟槸鍚︽槸鏂扮殑锛屽氨鎻掑叆鏃惰皟鐢save銆 鍦ㄦ瀯閫犲嚱鏁板拰populateRecord鑷姩璁剧疆姝ゅ睘鎬с 榛樿鍊间负false锛 濡傛灉浣跨敤new杩愮畻绗﹀垱寤哄疄渚嬶紝瀹冧細琚缃负true銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#799 (鏄剧ず)
public function getIsNewRecord()
{
    return 
$this->_new;
}

杩斿洖褰撳墠璁板綍鏄惁鏄柊鐨勩

getMetaData() 鏂规硶
public CActiveRecordMetaData getMetaData()
{return} CActiveRecordMetaData 杩欎釜AR绫荤殑鍏冩暟鎹
婧愮爜锛 framework/db/ar/CActiveRecord.php#389 (鏄剧ず)
public function getMetaData()
{
    if(
$this->_md!==null)
        return 
$this->_md;
    else
        return 
$this->_md=self::model(get_class($this))->_md;
}

杩斿洖杩欎釜AR鐨勫厓鏁版嵁銆

getOldPrimaryKey() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.0锛
public mixed getOldPrimaryKey()
{return} mixed 鏃х殑涓婚敭鍊笺傚垯杩斿洖鏁扮粍锛堝垪鍚=>鍒楀硷級濡傛灉涓婚敭鏄鍚堝瀷銆 If primary key is not defined, null will be returned.
婧愮爜锛 framework/db/ar/CActiveRecord.php#1255 (鏄剧ず)
public function getOldPrimaryKey()
{
    return 
$this->_pk;
}

杩斿洖鏃х殑涓婚敭鍊笺 杩欐寚鐨勬槸涓婚敭鍊煎凡濉厖鍒拌褰曞悗锛 鎵ц鏌ユ壘鏂规硶 (渚嬪锛 find()锛宖indAll())锛 鍗充娇涓诲叧閿睘鎬ч兘浼氳鎵嬪姩鍒嗛厤涓涓笉鍚岀殑鍊硷紝鍊间繚鎸佷笉鍙樸

getPrimaryKey() 鏂规硶
public mixed getPrimaryKey()
{return} mixed 涓婚敭鍊笺傚垯杩斿洖鏁扮粍锛堝垪鍚=>鍒楀硷級濡傛灉涓婚敭鏄鍚堝瀷銆 濡傛灉娌℃湁瀹氫箟涓婚敭锛屽皢杩斿洖null銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1210 (鏄剧ず)
public function getPrimaryKey()
{
    
$table=$this->getMetaData()->tableSchema;
    if(
is_string($table->primaryKey))
        return 
$this->{$table->primaryKey};
    else if(
is_array($table->primaryKey))
    {
        
$values=array();
        foreach(
$table->primaryKey as $name)
            
$values[$name]=$this->$name;
        return 
$values;
    }
    else
        return 
null;
}

杩斿洖涓婚敭鍊笺

getRelated() 鏂规硶
public mixed getRelated(string $name, boolean $refresh=false, array $params=array ( ))
$name string 鍏崇郴鍚 (鍙傝relations)
$refresh boolean 鏄惁浠庢暟鎹簱閲嶆柊杞藉叆鐩稿叧瀵硅薄锛岄粯璁ゅ间负false銆
$params array 闄勫姞鍙傛暟锛屽湪鍏崇郴澹版槑涓寚瀹氳嚜瀹氫箟鏌ヨ鏉′欢銆
{return} mixed 鐩稿叧瀵硅薄.
婧愮爜锛 framework/db/ar/CActiveRecord.php#242 (鏄剧ず)
public function getRelated($name,$refresh=false,$params=array())
{
    if(!
$refresh && $params===array() && (isset($this->_related[$name]) || array_key_exists($name,$this->_related)))
        return 
$this->_related[$name];

    
$md=$this->getMetaData();
    if(!isset(
$md->relations[$name]))
        throw new 
CDbException(Yii::t('yii','{class} does not have relation "{name}".',
            array(
'{class}'=>get_class($this), '{name}'=>$name)));

    
Yii::trace('lazy loading '.get_class($this).'.'.$name,'system.db.ar.CActiveRecord');
    
$relation=$md->relations[$name];
    if(
$this->getIsNewRecord() && !$refresh && ($relation instanceof CHasOneRelation || $relation instanceof CHasManyRelation))
        return 
$relation instanceof CHasOneRelation null : array();

    if(
$params!==array()) // dynamic query
    
{
        
$exists=isset($this->_related[$name]) || array_key_exists($name,$this->_related);
        if(
$exists)
            
$save=$this->_related[$name];
        
$r=array($name=>$params);
    }
    else
        
$r=$name;
    unset(
$this->_related[$name]);

    
$finder=new CActiveFinder($this,$r);
    
$finder->lazyFind($this);

    if(!isset(
$this->_related[$name]))
    {
        if(
$relation instanceof CHasManyRelation)
            
$this->_related[$name]=array();
        else if(
$relation instanceof CStatRelation)
            
$this->_related[$name]=$relation->defaultValue;
        else
            
$this->_related[$name]=null;
    }

    if(
$params!==array())
    {
        
$results=$this->_related[$name];
        if(
$exists)
            
$this->_related[$name]=$save;
        else
            unset(
$this->_related[$name]);
        return 
$results;
    }
    else
        return 
$this->_related[$name];
}

杩斿洖鐩稿叧鐨勮褰曘 杩欎釜鏂规硶灏嗚繑鍥炲綋鍓嶈褰曠殑鐩稿叧璁板綍銆 濡傛灉鍏崇郴鏄 HAS_ONE 鎴 BELONGS_TO锛 濡傛灉瀵硅薄涓嶅瓨鍦紝灏嗚繑鍥炰竴涓崟涓璞℃垨null銆 濡傛灉鍏崇郴鏄疕AS_MANY 鎴 MANY_MANY锛 瀹冭繑鍥炰竴涓璞℃暟缁勬垨涓涓┖鏁扮粍銆

getTableAlias() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.1锛
public string getTableAlias(boolean $quote=false, boolean $checkScopes=true)
$quote boolean 鏄惁瑕佸紩鐢ㄥ埆鍚
$checkScopes boolean 妫娴嬪埆鍚嶅綋鍓嶆槸鍚﹀湪搴旂敤鑼冨洿琚畾涔夈 璋冪敤defaultScope姝ゆ柟娉曟椂锛岃繖涓弬鏁板繀椤昏璁剧疆涓篺alse銆 鍚﹀垯灏嗗舰鎴愪竴涓棤闄愬惊鐜
{return} string 榛樿琛ㄥ埆鍚
婧愮爜锛 framework/db/ar/CActiveRecord.php#1358 (鏄剧ず)
public function getTableAlias($quote=false$checkScopes=true)
{
    if(
$checkScopes && ($criteria=$this->getDbCriteria(false))!==null && $criteria->alias!='')
        
$alias=$criteria->alias;
    else
        
$alias=$this->_alias;
    return 
$quote $this->getDbConnection()->getSchema()->quoteTableName($alias) : $alias;
}

杩斿洖鐢 find 鏂规硶浣跨敤琛ㄧ殑鍒悕銆 鍦ㄥ叧绯绘煡璇紝鏍规嵁瀵瑰簲鍏崇郴鐨勫0鏄庯紝 杩斿洖鐨勮〃鐨勫埆鍚嶅彲鑳戒細鏈夋墍涓嶅悓銆 姝ゅ锛岀敱setTableAlias鍙互鐢卞簲鐢ㄧ殑鑼冨洿瑕嗙洊銆

getTableSchema() 鏂规硶
public CDbTableSchema getTableSchema()
{return} CDbTableSchema 杩欎釜琛ㄧ殑鍏冩暟鎹睘浜嶢R绫
婧愮爜锛 framework/db/ar/CActiveRecord.php#637 (鏄剧ず)
public function getTableSchema()
{
    return 
$this->getMetaData()->tableSchema;
}

杩斿洖琛ㄧ殑鍏冩暟鎹紝杩欏睘浜嶢R绫汇

hasAttribute() 鏂规硶
public boolean hasAttribute(string $name)
$name string 灞炴у悕绉
{return} boolean 杩欐槸鍚︽槸AR鍛藉悕鐨勫睘鎬(table column).
婧愮爜锛 framework/db/ar/CActiveRecord.php#656 (鏄剧ず)
public function hasAttribute($name)
{
    return isset(
$this->getMetaData()->columns[$name]);
}

妫鏌ユAR鏄惁鏈夊懡鍚嶇殑灞炴с

hasRelated() 鏂规硶
public boolean hasRelated(string $name)
$name string 鍏崇郴鍚
{return} boolean 杩斿洖涓涓兼寚绀烘槸鍚﹀懡鍚嶇浉鍏冲璞¤杞藉叆銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#299 (鏄剧ず)
public function hasRelated($name)
{
    return isset(
$this->_related[$name]) || array_key_exists($name,$this->_related);
}

杩斿洖涓涓硷紝璇ュ兼寚绀烘槸鍚﹀凡鍔犺浇鍛藉悕鐨勭浉鍏冲璞°

init() 鏂规硶
public void init()
婧愮爜锛 framework/db/ar/CActiveRecord.php#93 (鏄剧ず)
public function init()
{
}

鍒濆鍖栬繖涓ā鍨嬨 褰撲竴涓狝R瀹炰緥鏄柊鍒涘缓鐨勬垨鏈夊畠鐨scenario璁剧疆锛 杩欎釜鏂规硶琚Е鍙戙 鎮ㄥ彲浠ラ噸鍐欐鏂规硶浠ユ彁渚涙墍闇鐨勫垵濮嬪寲鐨勪唬鐮佹ā鍨 (渚嬪锛氳缃垵濮嬬殑灞炴у)銆

insert() 鏂规硶
public boolean insert(array $attributes=NULL)
$attributes array 闇瑕佷繚瀛樼殑灞炴у垪琛ㄣ傞粯璁や负null锛 杩欐剰鍛崇潃浠庢暟鎹簱涓姞杞界殑鎵鏈夊睘鎬у皢琚繚瀛樸
{return} boolean 灞炴ф槸鍚︽湁鏁堬紝骞跺皢璁板綍鎻掑叆鎴愬姛銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1004 (鏄剧ず)
public function insert($attributes=null)
{
    if(!
$this->getIsNewRecord())
        throw new 
CDbException(Yii::t('yii','The active record cannot be inserted to database because it is not new.'));
    if(
$this->beforeSave())
    {
        
Yii::trace(get_class($this).'.insert()','system.db.ar.CActiveRecord');
        
$builder=$this->getCommandBuilder();
        
$table=$this->getMetaData()->tableSchema;
        
$command=$builder->createInsertCommand($table,$this->getAttributes($attributes));
        if(
$command->execute())
        {
            
$primaryKey=$table->primaryKey;
            if(
$table->sequenceName!==null)
            {
                if(
is_string($primaryKey) && $this->$primaryKey===null)
                    
$this->$primaryKey=$builder->getLastInsertID($table);
                else if(
is_array($primaryKey))
                {
                    foreach(
$primaryKey as $pk)
                    {
                        if(
$this->$pk===null)
                        {
                            
$this->$pk=$builder->getLastInsertID($table);
                            break;
                        }
                    }
                }
            }
            
$this->_pk=$this->getPrimaryKey();
            
$this->afterSave();
            
$this->setIsNewRecord(false);
            
$this->setScenario('update');
            return 
true;
        }
    }
    return 
false;
}

鎻掑叆涓琛屽埌鍩轰簬杩欎釜ActiveRecord鐨勫睘鎬ц〃銆 濡傛灉琛ㄧ殑涓婚敭鏄嚜鍔ㄥ閲忓拰鎻掑叆鍓嶄负null锛 灏嗘彃鍏ュ悗鐨勫疄闄呭煎~鍏呫 娉ㄦ剰锛岄獙璇佷笉鎵ц姝ゆ柟娉曘備綘鍙互璋冪敤validate鎵ц楠岃瘉銆 璁板綍鎴愬姛鎻掑叆鍒版暟鎹簱鍚庯紝瀹冪殑isNewRecord灞炴у皢璁剧疆涓篺alse锛 鍜屽畠鐨scenario灞炴у皢璁剧疆涓衡榰pdate鈥欍

instantiate() 鏂规硶
protected CActiveRecord instantiate(array $attributes)
$attributes array 娲诲姩璁板綍鐨勫睘鎬у煎垪琛ㄣ
{return} CActiveRecord 娲诲姩璁板綍
婧愮爜锛 framework/db/ar/CActiveRecord.php#1841 (鏄剧ず)
protected function instantiate($attributes)
{
    
$class=get_class($this);
    
$model=new $class(null);
    return 
$model;
}

鍒涘缓娲诲姩璁板綍瀹炰緥銆 杩欎釜鏂规硶璋冪敤populateRecordpopulateRecords銆 濡傛灉姝e湪鍒涘缓鐨勫疄渚嬶紝 浣犲彲浠ラ噸鍐欐鏂规硶锛屽彇鍐充簬濉厖绾綍鐨勫睘鎬с 渚嬪锛岄氳繃鍒涘缓鍩轰簬鍒楃殑鍊肩殑璁板綍锛 浣犲彲浠ュ疄鐜版墍璋撶殑鍗曡〃缁ф壙鏄犲皠銆

model() 鏂规硶
public static CActiveRecord model(string $className='CActiveRecord')
$className string 娲诲姩璁板綍绫荤殑鍚嶇О銆
{return} CActiveRecord 娲诲姩璁板綍妯″瀷鐨勪竴涓疄渚嬨
婧愮爜锛 framework/db/ar/CActiveRecord.php#372 (鏄剧ず)
public static function model($className=__CLASS__)
{
    if(isset(
self::$_models[$className]))
        return 
self::$_models[$className];
    else
    {
        
$model=self::$_models[$className]=new $className(null);
        
$model->_md=new CActiveRecordMetaData($model);
        
$model->attachBehaviors($model->behaviors());
        return 
$model;
    }
}

杩斿洖鎸囧畾AR绫荤殑闈欐佹ā鍨嬨 杩斿洖鐨勬ā鍨嬫槸涓涓潤鎬佺殑AR绫荤殑瀹炰緥銆 瀹冩彁渚涗簡鐢ㄤ簬璋冪敤绫荤骇鍒殑鏂规硶锛堟煇浜涗技涔庝簬闈欐佺被鏂规硶銆傦級

姣忎釜娲剧敓绫诲繀椤婚噸鍐欐鏂规硶濡備笅锛

public static function model($className=__CLASS__)
{
    return parent::model($className);
}

offsetExists() 鏂规硶
public boolean offsetExists(mixed $offset)
$offset mixed 妫鏌ュ埌鐨勫亸绉婚噺
{return} boolean
婧愮爜锛 framework/db/ar/CActiveRecord.php#1854 (鏄剧ず)
public function offsetExists($offset)
{
    return 
$this->__isset($offset);
}

杩斿洖鏄惁鏈夋寚瀹氬亸绉婚噺鐨勫厓绱犮 杩欑鏂规硶闇瑕佹帴鍙rrayAccess銆

onAfterDelete() 鏂规硶
public void onAfterDelete(CEvent $event)
$event CEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/db/ar/CActiveRecord.php#847 (鏄剧ず)
public function onAfterDelete($event)
{
    
$this->raiseEvent('onAfterDelete',$event);
}

鍦ㄥ垹闄よ褰曚箣鍚庯紝灏嗗紩鍙戞浜嬩欢銆

onAfterFind() 鏂规硶
public void onAfterFind(CEvent $event)
$event CEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/db/ar/CActiveRecord.php#870 (鏄剧ず)
public function onAfterFind($event)
{
    
$this->raiseEvent('onAfterFind',$event);
}

寮曞彂姝や簨浠惰褰曞悗鎵惧埌鏂规硶鐨勫疄渚嬨

onAfterSave() 鏂规硶
public void onAfterSave(CEvent $event)
$event CEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/db/ar/CActiveRecord.php#828 (鏄剧ず)
public function onAfterSave($event)
{
    
$this->raiseEvent('onAfterSave',$event);
}

淇濆瓨璁板綍涔嬪悗锛屽皢寮曞彂姝や簨浠躲

onBeforeDelete() 鏂规硶
public void onBeforeDelete(CModelEvent $event)
$event CModelEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/db/ar/CActiveRecord.php#838 (鏄剧ず)
public function onBeforeDelete($event)
{
    
$this->raiseEvent('onBeforeDelete',$event);
}

鍦ㄥ垹闄よ褰曚箣鍓嶏紝灏嗗紩鍙戞浜嬩欢銆 閫氳繃璁剧疆CModelEvent::isValid涓篺alse锛屾甯delete()杩涚▼琚仠姝€

onBeforeFind() 鏂规硶
public void onBeforeFind(CModelEvent $event)
$event CModelEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/db/ar/CActiveRecord.php#861 (鏄剧ず)
public function onBeforeFind($event)
{
    
$this->raiseEvent('onBeforeFind',$event);
}

AR finder鎵ц鏌ユ壘璋冪敤涔嬪墠锛屽皢寮曞彂姝や簨浠躲 鍦ㄨ繖绉嶆儏鍐典笅锛岃繖CModelEvent::criteria涓睘鎬т綔涓哄弬鏁颁紶閫掔粰姝ゆ柟娉曚綔涓烘煡璇㈡潯浠躲 濡傛灉浣犺璁块棶鑼冨洿涓寚瀹氱殑鏌ヨ鏉′欢锛 璇蜂娇鐢getDbCriteria()銆 浣犲彲浠ヤ慨鏀逛换浣曟潯浠讹紝鏍规嵁闇姹傚畾鍒躲

鍙傝

onBeforeSave() 鏂规硶
public void onBeforeSave(CModelEvent $event)
$event CModelEvent 浜嬩欢鍙傛暟
婧愮爜锛 framework/db/ar/CActiveRecord.php#819 (鏄剧ず)
public function onBeforeSave($event)
{
    
$this->raiseEvent('onBeforeSave',$event);
}

淇濆瓨璁板綍涔嬪墠锛屽皢寮曞彂姝や簨浠躲 閫氳繃璁剧疆CModelEvent::isValid涓篺alse锛屾甯save()杩涚▼琚仠姝€

populateRecord() 鏂规硶
public CActiveRecord populateRecord(array $attributes, boolean $callAfterFind=true)
$attributes array 灞炴у硷紙鍒楀悕=>鍒楀硷級
$callAfterFind boolean 鏄惁瑕佽褰曞悗璋冪敤afterFind濉厖銆
{return} CActiveRecord 鏂板垱寤虹殑娲诲姩璁板綍銆傜被鐨勫璞℃槸鐩稿悓鐨勬ā鍨嬬被銆 濡傛灉杈撳叆鐨勬暟鎹槸false锛屽垯杩斿洖null銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1781 (鏄剧ず)
public function populateRecord($attributes,$callAfterFind=true)
{
    if(
$attributes!==false)
    {
        
$record=$this->instantiate($attributes);
        
$record->setScenario('update');
        
$record->init();
        
$md=$record->getMetaData();
        foreach(
$attributes as $name=>$value)
        {
            if(
property_exists($record,$name))
                
$record->$name=$value;
            else if(isset(
$md->columns[$name]))
                
$record->_attributes[$name]=$value;
        }
        
$record->_pk=$record->getPrimaryKey();
        
$record->attachBehaviors($record->behaviors());
        if(
$callAfterFind)
            
$record->afterFind();
        return 
$record;
    }
    else
        return 
null;
}

缁欐寚瀹氱殑灞炴у垱寤烘椿鍔ㄨ褰 姝ゆ柟娉曠敱 find 鏂规硶鍐呴儴浣跨敤銆

populateRecords() 鏂规硶
public array populateRecords(array $data, boolean $callAfterFind=true, string $index=NULL)
$data array 娲诲姩璁板綍鐨勫睘鎬у煎垪琛ㄣ
$callAfterFind boolean 鏄惁瑕佽褰曞悗璋冪敤afterFind濉厖銆
$index string 鍏跺煎皢鐢ㄤ綔鏌ヨ缁撴灉鏁扮粍绱㈠紩灞炴х殑鍚嶇О銆 濡傛灉涓簄ull锛岃繖鎰忓懗鐫灏嗕粠闆跺紑濮嬬殑鏁存暟绱㈠紩鐨勬暟缁勩
{return} array 娲诲姩璁板綍鐨勫垪琛
婧愮爜锛 framework/db/ar/CActiveRecord.php#1815 (鏄剧ず)
public function populateRecords($data,$callAfterFind=true,$index=null)
{
    
$records=array();
    foreach(
$data as $attributes)
    {
        if((
$record=$this->populateRecord($attributes,$callAfterFind))!==null)
        {
            if(
$index===null)
                
$records[]=$record;
            else
                
$records[$record->$index]=$record;
        }
    }
    return 
$records;
}

鍒涘缓鍩轰簬杈撳叆鏁版嵁鐨勬椿鍔ㄨ褰曠殑鍒楄〃銆 姝ゆ柟娉曠敱 find 鏂规硶鍐呴儴浣跨敤銆

primaryKey() 鏂规硶
public mixed primaryKey()
{return} mixed 鐩稿叧鏁版嵁琛ㄧ殑涓婚敭銆 濡傛灉璇ラ敭鏄竴涓崟涓鐨勫垪锛屽畠搴斿綋杩斿洖鍒楃殑鍚嶇О锛 濡傛灉閿槸鐢卞涓垪缁勬垚鐨勫鍚堥敭, 瀹冨簲璇ヨ繑鍥炴暟缁勭殑閿垪鍚嶇О銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#434 (鏄剧ず)
public function primaryKey()
{
}

杩斿洖鐩稿叧鏁版嵁搴撹〃鐨勪富閿 杩欑鏂规硶鏄寚琛ㄦ病鏈夊畾涔変富閿椂锛堜竴浜沴egency鏁版嵁搴擄級鐨勬儏鍐典笅閲嶅啓銆 濡傛灉琛ㄥ凡瀹氫箟涓婚敭锛 浣犱笉闇瑕侀噸鍐欐鏂规硶銆傞粯璁ゅ疄鐜板彧杩斿洖null锛 鎰忔濇槸杩斿洖鍦ㄦ暟鎹簱涓畾涔夌殑涓婚敭銆

query() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.7锛
protected mixed query(CDbCriteria $criteria, boolean $all=false)
$criteria CDbCriteria the query criteria
$all boolean whether to return all data
{return} mixed the AR objects populated with the query result
婧愮爜锛 framework/db/ar/CActiveRecord.php#1278 (鏄剧ず)
protected function query($criteria,$all=false)
{
    
$this->beforeFind();
    
$this->applyScopes($criteria);
    if(empty(
$criteria->with))
    {
        if(!
$all)
            
$criteria->limit=1;
        
$command=$this->getCommandBuilder()->createFindCommand($this->getTableSchema(),$criteria);
        return 
$all $this->populateRecords($command->queryAll(), true$criteria->index) : $this->populateRecord($command->queryRow());
    }
    else
    {
        
$finder=new CActiveFinder($this,$criteria->with);
        return 
$finder->query($criteria,$all);
    }
}

鎵ц瀹為檯鐨勬暟鎹簱鏌ヨ鍜屽~鍏匒R瀵硅薄鐨勬煡璇㈢粨鏋溿 姝ゆ柟娉曠敱鍏朵粬 AR 鏌ヨ鏂规硶璋冪敤锛屼富瑕佹槸鍐呴儴浣跨敤銆

refresh() 鏂规硶
public boolean refresh()
{return} boolean 璇ヨ鏄惁浠嶇劧瀛樺湪浜庢暟鎹簱涓傚鏋滄儏鍐靛睘瀹烇紝鏈鏂扮殑鏁版嵁灏嗚濉厖鍒拌繖涓椿鍔ㄨ褰曘
婧愮爜锛 framework/db/ar/CActiveRecord.php#1174 (鏄剧ず)
public function refresh()
{
    
Yii::trace(get_class($this).'.refresh()','system.db.ar.CActiveRecord');
    if(!
$this->getIsNewRecord() && ($record=$this->findByPk($this->getPrimaryKey()))!==null)
    {
        
$this->_attributes=array();
        
$this->_related=array();
        foreach(
$this->getMetaData()->columns as $name=>$column)
        {
            if(
property_exists($this,$name))
                
$this->$name=$record->$name;
            else
                
$this->_attributes[$name]=$record->$name;
        }
        return 
true;
    }
    else
        return 
false;
}

鏈鏂扮殑鏁版嵁灏嗚濉厖鍒拌繖涓椿鍔ㄨ褰曘

refreshMetaData() 鏂规硶
public void refreshMetaData()
婧愮爜锛 framework/db/ar/CActiveRecord.php#404 (鏄剧ず)
public function refreshMetaData()
{
    
$finder=self::model(get_class($this));
    
$finder->_md=new CActiveRecordMetaData($finder);
    if(
$this!==$finder)
        
$this->_md=$finder->_md;
}

鍒锋柊杩欎釜AR绫荤殑鍏冩暟鎹 閫氳繃璋冪敤杩欎釜鏂规硶锛岃繖涓狝R绫诲皢閲嶆柊鐢熸垚闇瑕佺殑鍏冩暟鎹 濡傛灉琛ㄧ殑缁撴瀯宸茬粡鏀瑰彉锛屼笖浣犳兂瑕佷娇鐢ㄦ渶鏂扮殑锛岃繖鏄潪甯告湁鐢ㄧ殑銆 鍦ㄤ綘璋冪敤杩欎釜鏂规硶鍓嶏紝纭繚浣犲凡缁忚皟鐢CDbSchema::refresh锛 瑕佷笉鐒讹紝鏃ц〃鐨勭殑鏁版嵁缁撴瀯浠嶈浣跨敤銆

relations() 鏂规硶
public array relations()
{return} array 鐩稿叧瀵硅薄鐢虫槑鍒楄〃銆 榛樿鍊间负绌烘暟缁勩
婧愮爜锛 framework/db/ar/CActiveRecord.php#517 (鏄剧ず)
public function relations()
{
    return array();
}

鐢虫槑鍏崇郴鐨勫璞★紝搴旈噸鍐欐鏂规硶銆

鍙兘瀛樺湪涓や釜娲诲姩璁板綍瀵硅薄涔嬮棿鐨勫叧绯绘湁鍥涚绫诲瀷锛



闄や簡涓婅堪鐨勫叧绯荤被鍨嬶紝 杩樻敮鎸佷竴绉嶇壒娈婄殑鍏崇郴绉颁负STAT锛屽彲浠ョ敤鏉ヨ繘琛岀粺璁℃煡璇紙鎴栬仛鍚堟煡璇級銆 瀹冩绱㈣仛鍚堝鐩稿叧瀵硅薄鐨勪俊鎭紝 濡傛瘡涓笘瀛愶紝瀵逛簬姣忎釜浜у搧锛屽钩鍧囧垎鏁颁负娉ㄩ噴鐨勬暟鐩瓑銆

鐩稿叧瀵硅薄鐨勬瘡涓被瀹氫箟鍦ㄦ鏂规硶涓綔涓哄叿鏈変互涓嬪厓绱犵殑鏁扮粍锛
'varName'=>array('relationType', 'className', 'foreign_key', ...additional options)
鍏朵腑鈥榲arName鈥欐槸鎵瑰彉閲/灞炴х殑鍚嶇О锛屽彲浠ラ氳繃瀵硅薄鏉ヨ闂紱 鈥榬elationType鈥欐槸鎸囧叧绯荤殑绫诲瀷锛屽畠鍙互鏄互涓嬪洓绉嶅父閲忎箣涓锛 self::BELONGS_TO锛宻elf::HAS_ONE锛宻elf::HAS_MANY 鍜 self::MANY_MANY锛 鈥榗lassName鈥欐槸鎸囨椿鍔ㄨ褰曠被鐨勭浉鍏冲璞$殑鍚嶇О锛 鍜屸榝oreign_key鈥欒瀹氱殑澶栭敭娑夊強涓ょ娲诲姩璁板綍銆 璇锋敞鎰忓鍚堝閿紝 浠栦滑鍙互涓璧峰垪鍑猴紝浠ラ楀彿鍒嗛殧锛屾垨鑰呬綔涓轰竴涓暟缁勬寚瀹氭暟缁勭殑鏍煎紡锛堚榢ey1锛宬ey2鈥欙級銆 濡傛灉浣犻渶瑕佹寚瀹氳嚜瀹氫箟鐨刾k->fk鍏宠仈锛屼綘鍙互瀹氫箟鏁扮粍锛堚榝k鈥=> 鈥榩k'锛夈 瀵逛簬缁勫悎閿繖灏嗘槸鏁扮粍锛堚榝k_c1鈥=>鈥榩k_褋1鈥欙紝鈥榝k_c2鈥=>鈥榩k_c2鈥欙級銆 MANY_MANY鍏崇郴涓娇鐢ㄥ閿紝 鍔犲叆琛ㄥ繀椤诲0鏄庝负锛堜緥濡傦細鈥榡oin_table(fk1锛宖k2)鈥欙級銆

鍏朵綑鏁扮粍鍏冪礌鐨勫悕绉-鍊硷紝鍙互鎸囧畾鍏朵粬閫夐」锛

寤惰繜鍔犺浇鏃舵湁涓瀹氱殑鍏崇郴锛屼笅鍒楅夐」鍙敤锛

浠ヤ笅鏄竴涓緥瀛愶紝涓 'Post' 娲诲姩璁板綍绫荤浉鍏冲璞$殑涓涓ず渚嬶細
return array(
    'author'=>array(self::BELONGS_TO, 'User', 'author_id'),
    'comments'=>array(self::HAS_MANY, 'Comment', 'post_id', 'with'=>'author', 'order'=>'create_time DESC'),
    'tags'=>array(self::MANY_MANY, 'Tag', 'post_tag(post_id, tag_id)', 'order'=>'name'),
);

resetScope() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.2锛
public CActiveRecord resetScope()
{return} CActiveRecord
婧愮爜锛 framework/db/ar/CActiveRecord.php#350 (鏄剧ず)
public function resetScope()
{
    
$this->_c=new CDbCriteria();
    return 
$this;
}

閲嶇疆鎵鏈夊彉閲忎綔鐢ㄥ煙锛屽寘鎷粯璁ょ殑鑼冨洿銆

save() 鏂规硶
public boolean save(boolean $runValidation=true, array $attributes=NULL)
$runValidation boolean 淇濆瓨璁板綍涔嬪墠鏄惁鎵ц楠岃瘉銆 濡傛灉楠岃瘉澶辫触锛岃褰曚笉浼氳淇濆瓨鍒版暟鎹簱銆
$attributes array 闇瑕佷繚瀛樼殑灞炴у垪琛ㄣ 榛樿涓簄ull锛岃繖鎰忓懗鐫浠庢暟鎹簱涓姞杞界殑鎵鏈夊睘鎬у皢琚繚瀛樸
{return} boolean whether the saving succeeds
婧愮爜锛 framework/db/ar/CActiveRecord.php#784 (鏄剧ず)
public function save($runValidation=true,$attributes=null)
{
    if(!
$runValidation || $this->validate($attributes))
        return 
$this->getIsNewRecord() ? $this->insert($attributes) : $this->update($attributes);
    else
        return 
false;
}

淇濆瓨褰撳墠鐨勮褰曘

鎻掑叆璁板綍鍒版暟鎹〃鐨勪竴琛岋紝 濡傛灉瀹冪殑isNewRecord灞炴т负true锛堥氬父鎯呭喌涓嬩娇鐢ㄧ殑鈥榥ew鈥欒繍绠楃鏉ュ垱寤鸿褰曪級銆 鍚﹀垯锛 灏嗚鐢ㄤ簬鏇存柊琛ㄤ腑鐨勭浉搴旇锛堥氬父鎯呭喌涓嬶紝浣跨敤鈥榝ind鈥欐柟娉曟潵鏌ユ壘璁板綍锛夈

淇濆瓨璁板綍涔嬪墠灏嗘墽琛岄獙璇併 濡傛灉楠岃瘉澶辫触锛岃璁板綍灏嗕笉浼氫繚瀛樸 浣犲彲浠ヨ皟鐢getErrors()妫绱㈤獙璇侀敊璇

濡傛灉璇ヨ褰曢氳繃鎻掑叆淇濆瓨锛 瀹isNewRecord鐨勫睘鎬т細琚缃负false锛屽拰瀹冪殑scenario灞炴ц璁剧疆涓衡榰pdate鈥欍 濡傛灉鍏朵富閿槸鑷姩澧為噺锛屽苟涓斿湪鎻掑叆涔嬪墠鏈缃紝 灏嗕娇鐢ㄨ嚜鍔ㄧ敓鎴愮殑鍊兼潵濉厖涓婚敭銆

saveAttributes() 鏂规硶
public boolean saveAttributes(array $attributes)
$attributes array 瑕佹洿鏂扮殑灞炴с 姣忎釜鍏冪礌琛ㄧず鐨勫睘鎬у悕绉版垨鎸夊叾鍚嶇О绱㈠紩鐨勫睘鎬у笺 濡傛灉鏄悗鑰咃紝璁板綍鐨勫睘鎬у皢鎹涔嬪墠淇濆瓨鐨勬洿鏀广
{return} boolean 鏇存柊鏄惁鎴愬姛
婧愮爜锛 framework/db/ar/CActiveRecord.php#1088 (鏄剧ず)
public function saveAttributes($attributes)
{
    if(!
$this->getIsNewRecord())
    {
        
Yii::trace(get_class($this).'.saveAttributes()','system.db.ar.CActiveRecord');
        
$values=array();
        foreach(
$attributes as $name=>$value)
        {
            if(
is_integer($name))
                
$values[$value]=$this->$value;
            else
                
$values[$name]=$this->$name=$value;
        }
        if(
$this->_pk===null)
            
$this->_pk=$this->getPrimaryKey();
        if(
$this->updateByPk($this->getOldPrimaryKey(),$values)>0)
        {
            
$this->_pk=$this->getPrimaryKey();
            return 
true;
        }
        else
            return 
false;
    }
    else
        throw new 
CDbException(Yii::t('yii','The active record cannot be updated because it is new.'));
}

淇濆瓨鎵閫夌殑灞炴у垪琛ㄣ 涓嶅悓浜save锛岃繖涓柟娉曞彧淇濆瓨鐜版湁鐨勫垪鏁版嵁闆嗙殑鎸囧畾鐨勫睘鎬э紝 骞朵笖涓嶈皟鐢beforeSaveafterSave銆 璇锋敞鎰忚繖涓柟娉曚笉杩囨护灞炴т篃涓嶅仛楠岃瘉銆 鎵浠ヤ笉瑕佽繖绉嶆柟娉曟帴鍙椾笉鍙椾俊浠荤殑鏁版嵁锛堝鐢ㄦ埛鍙戝竷鐨勬暟鎹級銆 濡傛灉浣犳兂杩欐牱鍋氾紝鍙互鑰冭檻浠ヤ笅鏂规硶浠f浛锛

$postRecord=Post::model()->findByPk($postID);
$postRecord->attributes=$_POST['post'];
$postRecord->save();

saveCounters() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.8锛
public boolean saveCounters(array $counters)
$counters array 瑕佹洿鏂拌鏁板櫒锛堝垪鍚=>澧為噺鍊硷級
{return} boolean 淇濆瓨鏄惁鎴愬姛
婧愮爜锛 framework/db/ar/CActiveRecord.php#1130 (鏄剧ず)
public function saveCounters($counters)
{
    
Yii::trace(get_class($this).'.saveCounters()','system.db.ar.CActiveRecord');
    
$builder=$this->getCommandBuilder();
    
$table=$this->getTableSchema();
    
$criteria=$builder->createPkCriteria($table,$this->getOldPrimaryKey());
    
$command=$builder->createUpdateCounterCommand($this->getTableSchema(),$counters,$criteria);
    if(
$command->execute())
    {
        foreach(
$counters as $name=>$value)
            
$this->$name=$this->$name+$value;
        return 
true;
    }
    else
        return 
false;
}

淇濆瓨涓涓垨澶氬綋鍓岮R瀵硅薄鍒拌鏁板櫒銆 璇锋敞鎰忥紝姝ゆ柟娉曚笉鍚屼簬updateCounters 锛 瀹冨彧淇濆瓨褰撳墠AR瀵硅薄銆 鐢ㄦ硶绀轰緥濡備笅鎵绀猴細

$postRecord=Post::model()->findByPk($postID);
$postRecord->saveCounters(array('view_count'=>1));
濡傛灉浣犳兂鍑忓皯璁℃暟鍣紝璇蜂娇鐢ㄨ礋鍊笺

鍙傝

scopes() 鏂规硶
public array scopes()
{return} array 鑼冨洿鐨勭晫瀹氥傛暟缁勪腑鐨勯敭鑼冨洿鍚嶇О; 鏁扮粍涓殑鍊兼槸鐩稿簲鐨勮寖鍥村畾涔夈 姣忎釜鑼冨洿瀹氫箟琚〃绀轰负涓涓暟缁勶紝鍏堕敭蹇呴』鏄CDbCriteria鐨勫睘鎬с
婧愮爜锛 framework/db/ar/CActiveRecord.php#553 (鏄剧ず)
public function scopes()
{
    return array();
}

杩斿洖鐢虫槑鐨勫懡鍚嶈寖鍥淬 浠h〃涓涓煡璇㈡潯浠剁殑鍛藉悕鑼冨洿锛屽彲浠ヤ覆杩炲湪涓璧蜂笌鍏朵粬鐨勫懡鍚嶈寖鍥村拰鏌ヨ銆 杩欑鏂规硶搴旇閲嶅啓锛 瀛愮被澹版槑涓虹壒瀹氱殑AR绫荤殑鍛藉悕鑼冨洿銆 渚嬪锛 涓嬮潰鐨勪唬鐮佸0鏄庝袱涓懡鍚嶈寖鍥粹榬ecently鈥欏拰鈥榩ublished鈥欍

return array(
    'published'=>array(
          'condition'=>'status=1',
    ),
    'recently'=>array(
          'order'=>'create_time DESC',
          'limit'=>5,
    ),
);
濡傛灉涓婅堪鑼冨洿鐨勭敵鏄庡湪Post妯″瀷锛 鎴戜滑鍙互鎵ц浠ヤ笅鏌ヨ锛
$posts=Post::model()->published()->findAll();
$posts=Post::model()->published()->recently()->findAll();
$posts=Post::model()->published()->with('comments')->findAll();
闇瑕佹敞鎰忕殑鏄渶鍚庝竴涓煡璇㈡槸涓涓叧鑱旀煡璇€

setAttribute() 鏂规硶
public boolean setAttribute(string $name, mixed $value)
$name string 灞炴у悕绉
$value mixed 灞炴у
{return} boolean 灞炴ф槸鍚﹀瓨鍦ㄥ拰浠诲姟鎴愬姛杩涜
婧愮爜锛 framework/db/ar/CActiveRecord.php#688 (鏄剧ず)
public function setAttribute($name,$value)
{
    if(
property_exists($this,$name))
        
$this->$name=$value;
    else if(isset(
$this->getMetaData()->columns[$name]))
        
$this->_attributes[$name]=$value;
    else
        return 
false;
    return 
true;
}

璁剧疆鍛藉悕鐨勫睘鎬у笺 浣犱篃鍙互浣跨敤$this->AttributeName鏉ヨ缃睘鎬у笺

鍙傝

setDbCriteria() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.3锛
public void setDbCriteria(CDbCriteria $criteria)
$criteria CDbCriteria 鏌ヨ鏉′欢
婧愮爜锛 framework/db/ar/CActiveRecord.php#326 (鏄剧ず)
public function setDbCriteria($criteria)
{
    
$this->_c=$criteria;
}

涓哄綋鍓嶆ā鍨嬭缃煡璇㈡潯浠.

setIsNewRecord() 鏂规硶
public void setIsNewRecord(boolean $value)
$value boolean 璇ヨ褰曟槸鍚︽槸鏂扮殑锛屽氨鎻掑叆鏃惰皟鐢save
婧愮爜锛 framework/db/ar/CActiveRecord.php#809 (鏄剧ず)
public function setIsNewRecord($value)
{
    
$this->_new=$value;
}

璁剧疆璁板綍鏄惁鏄柊鐨勩

鍙傝

setOldPrimaryKey() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.3锛
public void setOldPrimaryKey(mixed $value)
$value mixed 鏃т富閿笺
婧愮爜锛 framework/db/ar/CActiveRecord.php#1265 (鏄剧ず)
public function setOldPrimaryKey($value)
{
    
$this->_pk=$value;
}

璁剧疆鏃х殑涓婚敭鍊笺

setPrimaryKey() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.0锛
public void setPrimaryKey(mixed $value)
$value mixed 鏂扮殑涓婚敭鍊笺傚鏋滀富閿槸澶嶅悎绫诲瀷锛 搴旀彁渚涗竴涓柊鍊煎仛涓烘暟缁勶紙鍒楀悕=>鍒楀硷級銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1233 (鏄剧ず)
public function setPrimaryKey($value)
{
    
$this->_pk=$this->getPrimaryKey();
    
$table=$this->getMetaData()->tableSchema;
    if(
is_string($table->primaryKey))
        
$this->{$table->primaryKey}=$value;
    else if(
is_array($table->primaryKey))
    {
        foreach(
$table->primaryKey as $name)
            
$this->$name=$value[$name];
    }
}

璁剧疆涓婚敭鍊笺 璋冪敤姝ゆ柟娉曞悗锛屾棫鐨勪富閿硷紝鍙互浠oldPrimaryKey寰楀埌銆

setTableAlias() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.3锛
public void setTableAlias(string $alias)
$alias string 鍦ㄦ煡璇腑浣跨敤琛ㄧ殑鍒悕銆傚埆鍚嶄笉搴旇鍔犲紩鍙枫
婧愮爜锛 framework/db/ar/CActiveRecord.php#1372 (鏄剧ず)
public function setTableAlias($alias)
{
    
$this->_alias=$alias;
}

璁剧疆琛ㄥ湪鏌ヨ涓娇鐢ㄧ殑鍒悕銆

tableName() 鏂规硶
public string tableName()
{return} string 杩斿洖琛ㄥ悕
婧愮爜锛 framework/db/ar/CActiveRecord.php#418 (鏄剧ず)
public function tableName()
{
    return 
get_class($this);
}

杩斿洖鍏宠仈鐨勬暟鎹簱琛ㄧ殑鍚嶇О銆 榛樿鎯呭喌涓嬶紝杩欎釜鏂规硶杩斿洖绫诲悕浣滀负琛ㄥ悕銆 浣犲彲浠ヨ鐩栬繖涓柟娉曪紝濡傛灉姝ゅ垪娌℃湁鍛藉悕鍦ㄨ繖娆$害瀹氫箣鍚庛

together() 鏂规硶 锛堝彲鐢ㄨ嚜 v1.1.4锛
public CActiveRecord together()
{return} CActiveRecord AR瀵硅薄鏈韩銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1658 (鏄剧ず)
public function together()
{
    
$this->getDbCriteria()->together=true;
    return 
$this;
}

璁剧疆CDbCriteria::together灞炴т负true銆 杩欏彧鐢ㄤ簬鍏崇郴AR鏌ヨ銆 璇峰弬瑙CDbCriteria::together鏇村璇︾粏銆

update() 鏂规硶
public boolean update(array $attributes=NULL)
$attributes array 闇瑕佷繚瀛樼殑灞炴у垪琛ㄣ傞粯璁や负null锛 杩欐剰鍛崇潃浠庢暟鎹簱涓姞杞界殑鎵鏈夊睘鎬у皢琚繚瀛樸
{return} boolean 鏇存柊鏄惁鎴愬姛
婧愮爜锛 framework/db/ar/CActiveRecord.php#1052 (鏄剧ず)
public function update($attributes=null)
{
    if(
$this->getIsNewRecord())
        throw new 
CDbException(Yii::t('yii','The active record cannot be updated because it is new.'));
    if(
$this->beforeSave())
    {
        
Yii::trace(get_class($this).'.update()','system.db.ar.CActiveRecord');
        if(
$this->_pk===null)
            
$this->_pk=$this->getPrimaryKey();
        
$this->updateByPk($this->getOldPrimaryKey(),$this->getAttributes($attributes));
        
$this->_pk=$this->getPrimaryKey();
        
$this->afterSave();
        return 
true;
    }
    else
        return 
false;
}

鏇存柊姝ゆ椿鍔ㄨ褰曟墍琛ㄧず鐨勮銆 宸插姞杞界殑鎵鏈夊睘鎬ч兘灏嗕繚瀛樺埌鏁版嵁搴撲腑銆 娉ㄦ剰锛岄獙璇佷笉鎵ц姝ゆ柟娉曘備綘鍙互璋冪敤validate鎵ц楠岃瘉銆

updateAll() 鏂规硶
public integer updateAll(array $attributes, mixed $condition='', array $params=array ( ))
$attributes array 鐢ㄤ簬鏇存柊鐨勫睘鎬у垪琛紙name=>$value锛夈
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} integer 琚洿鏂扮殑琛屾暟
婧愮爜锛 framework/db/ar/CActiveRecord.php#1693 (鏄剧ず)
public function updateAll($attributes,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.updateAll()','system.db.ar.CActiveRecord');
    
$builder=$this->getCommandBuilder();
    
$criteria=$builder->createCriteria($condition,$params);
    
$command=$builder->createUpdateCommand($this->getTableSchema(),$attributes,$criteria);
    return 
$command->execute();
}

鏇存柊浣跨敤鎸囧畾鏉′欢鐨勮褰曘 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆 娉ㄦ剰锛屽睘鎬ф病鏈夊仛瀹夊叏妫娴嬪拰鏍¢獙銆

updateByPk() 鏂规硶
public integer updateByPk(mixed $pk, array $attributes, mixed $condition='', array $params=array ( ))
$pk mixed 涓婚敭鍊笺傚澶氫釜涓婚敭浣跨敤鏁扮粍銆傚鍚堥敭锛屽浜庢瘡涓敭鐨勫煎繀椤绘槸涓涓暟缁勶紙鍒楀悕=>鍒楀硷級銆
$attributes array 鐢ㄤ簬鏇存柊鐨勫睘鎬у垪琛紙name=>$value锛夈
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} integer 琚洿鏂扮殑琛屾暟
婧愮爜锛 framework/db/ar/CActiveRecord.php#1674 (鏄剧ず)
public function updateByPk($pk,$attributes,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.updateByPk()','system.db.ar.CActiveRecord');
    
$builder=$this->getCommandBuilder();
    
$table=$this->getTableSchema();
    
$criteria=$builder->createPkCriteria($table,$pk,$condition,$params);
    
$command=$builder->createUpdateCommand($table,$attributes,$criteria);
    return 
$command->execute();
}

鏇存柊鎸囧畾涓婚敭璁板綍鐨勮銆 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆 娉ㄦ剰锛屽睘鎬ф病鏈夊仛瀹夊叏妫娴嬪拰鏍¢獙銆

updateCounters() 鏂规硶
public integer updateCounters(array $counters, mixed $condition='', array $params=array ( ))
$counters array 瑕佹洿鏂扮殑璁℃暟鍣紙鍒楀悕=>澧為噺鍊硷級
$condition mixed 鏌ヨ鏉′欢鎴栨爣鍑嗐
$params array 瑕佺粦瀹氬埌鐨 SQL 璇彞鐨勫弬鏁
{return} integer 琚洿鏂扮殑琛屾暟
婧愮爜锛 framework/db/ar/CActiveRecord.php#1712 (鏄剧ず)
public function updateCounters($counters,$condition='',$params=array())
{
    
Yii::trace(get_class($this).'.updateCounters()','system.db.ar.CActiveRecord');
    
$builder=$this->getCommandBuilder();
    
$criteria=$builder->createCriteria($condition,$params);
    
$command=$builder->createUpdateCounterCommand($this->getTableSchema(),$counters,$criteria);
    return 
$command->execute();
}

鏇存柊鐨勪竴涓垨澶氫釜璁℃暟鍣ㄣ 璇锋敞鎰忥紝闄ら潪鎸囧畾涓涓潯浠舵垨鏍囧噯锛岃繖灏嗘洿鏂版墍鏈夋暟鎹銆 鍙傝find()璇︾粏璇存槑鍏充簬$condition鍜$params銆

鍙傝

with() 鏂规硶
public CActiveRecord with()
{return} CActiveRecord AR瀵硅薄鏈韩銆
婧愮爜锛 framework/db/ar/CActiveRecord.php#1638 (鏄剧ず)
public function with()
{
    if(
func_num_args()>0)
    {
        
$with=func_get_args();
        if(
is_array($with[0]))  // the parameter is given as an array
            
$with=$with[0];
        if(!empty(
$with))
            
$this->getDbCriteria()->mergeWith(array('with'=>$with));
    }
    return 
$this;
}

鎸囧畾鐩稿叧瀵硅薄搴斾竴璧疯浇鍏ャ 杩欎釜鏂规硶閲囧彇鍙橀噺鐨勫弬鏁般 姣忎釜鍙傛暟鎸囧畾鍏崇郴鎴栧瓙鍏崇郴鐨勫悕绉般備緥濡傦紝

// find all posts together with their author and comments
Post::model()->with('author','comments')->findAll();
// find all posts together with their author and the author's profile
Post::model()->with('author','author.profile')->findAll();
搴旂敤涓0鏄庣殑鍏崇郴relations()

榛樿鎯呭喌涓嬶紝鍦ㄦ寚瀹氱殑relations()閫夐」灏嗚鐢ㄦ潵鍋氬叧鑱旀煡璇€ 涓轰簡鑷畾涔夊姩鎬侀夐」锛屾垜浠簲灏嗕竴涓暟缁勫弬鏁颁紶閫掔粰 with() 鏂规硶銆 鏁扮粍鐨勯敭鏄叧绯荤殑鍚嶇О锛 鍜屾暟缁勫煎搴旂殑鏌ヨ閫夐」銆 渚嬪锛
Post::model()->with(array(
    'author'=>array('select'=>'id, name'),
    'comments'=>array('condition'=>'approved=1', 'order'=>'create_time'),
))->findAll();

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