當前位置: 首頁>>代碼示例>>PHP>>正文


PHP CModel::relations方法代碼示例

本文整理匯總了PHP中CModel::relations方法的典型用法代碼示例。如果您正苦於以下問題:PHP CModel::relations方法的具體用法?PHP CModel::relations怎麽用?PHP CModel::relations使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在CModel的用法示例。


在下文中一共展示了CModel::relations方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: init

 /**
  * Initializes the widget.
  * This method is called by {@link CBaseController::createWidget}
  * and {@link CBaseController::beginWidget} after the widget's
  * properties have been initialized.
  */
 public function init()
 {
     // check that the necessary info has been passed in to the widget
     if (!$this->hasModelRelation()) {
         throw new CException(Yii::t('yii', '{class} must specify "model" and "relation" values.', array('{class}' => get_class($this))));
     }
     // set the name if there is an override
     //$this->resolveName();
     // Sort out the type of relation, and set it up accordingly
     $relations = $this->model->relations();
     // $key = Name of the Relation
     // $value[0] = Type of the Relation
     // $value[1] = Related Model
     // $value[2] = Related Field or Many_Many Table
     if ($details = $relations[$this->relation]) {
         $this->_relationType = $details[0];
         // save the type of relation
         $this->_relatedModel = new $details[1]();
         // set up an model of the related kind
         $this->_relatedModelPk = $this->_relatedModel->tableSchema->primaryKey;
         // get the related model's primay key
         switch ($this->_relationType) {
             case 'CBelongsToRelation':
                 $this->setupBelongsTo($details);
                 break;
             case 'CHasOneRelation':
                 throw new CException('CHasOneRelation not supported by SRelationWidget yet');
                 // todo handle HasOne relations
                 //$this->setupHasOne($details);
                 break;
             case 'CManyManyRelation':
                 $this->setupManyMany($details);
                 break;
             case 'CHasManyRelation':
                 throw new CException('CHasManyRelation not supported by SRelationWidget yet');
                 // todo handle HasMany relations
                 //$this->setupHasMany($details);
                 break;
             default:
                 throw new CException('Unknown relation type for SRelationWidget');
         }
     }
 }
開發者ID:narwold,項目名稱:Small-Potatoes,代碼行數:49,代碼來源:SRelationWidget.php


注:本文中的CModel::relations方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。