From 976accaf27a572a25a4eb4d1cd2e438329cca232 Mon Sep 17 00:00:00 2001 From: XAKEPEHOK Date: Wed, 30 Jan 2013 14:50:16 +0400 Subject: [PATCH] Update Comment model MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit For using commentsWidget inside others modules  we load model from module through 'modelAlias' param in main.php 'commentableModels'=>array(    //model with individual settings    'Blog' => array(      'modelAlias' => 'application.modules.blog.models.Blog',    ), ), --- models/Comment.php | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/models/Comment.php b/models/Comment.php index 2463150..91d80a3 100644 --- a/models/Comment.php +++ b/models/Comment.php @@ -332,6 +332,21 @@ public function getOwnerModel() else $key = array_combine($primaryKey, explode('.', $this->owner_id)); $ownerModel = $this->owner_name; + + /* + * For using commentsWidget inside others modules + * we load model from module through 'modelAlias' param + * Example: + * 'commentableModels'=>array( + * //model with individual settings + * 'Blog' => array( + * 'modelAlias' => 'application.modules.blog.models.Blog', + * ), + * ), + * */ + $commentsModule = Yii::app()->getModule('comments'); + $config = $commentsModule->getModelConfig($ownerModel); + if (isset($config['modelAlias'])) Yii::import($config['modelAlias']); if(class_exists($ownerModel)) $this->_ownerModel = CActiveRecord::model($ownerModel)->findByPk($key); @@ -412,4 +427,4 @@ public function beforeSave() { return parent::beforeSave(); } -} \ No newline at end of file +}