当前位置: 首页>>代码示例>>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;未经允许,请勿转载。