如何在模型类中获取变量$mapCommentColumn
的值?
这是CommentableBehavior
modules/comment/behaviors/CommentableBehavior.php
课程
class CommentableBehavior extends CActiveRecordBehavior
{
/**
* @var string name of the table defining the relation with comment and model
*/
public $mapTable = null;
/**
* @var string name of the table column holding commentId in mapTable
*/
public $mapCommentColumn = 'commentId';
/**
* @var string name of the table column holding related Objects Id in mapTable
*/
public $mapRelatedColumn = null;
.......
}
在modules/comment/models/comment.php
protected function beforeSave()
{
$commentedModel = CActiveRecord::model($this->module->commentableModels[$this->type]);
$db = array(
'join' => "JOIN " . $this->mapTable . " cm ON t.id = cm." . $this->mapCommentColumn,
'condition' => "cm." . $this->mapYearColumn . "=:year
AND t.pending=:pending",
'params' => array(':year'=>$_GET['year'], ':pending'=>0)
);
print_r(CommentableBehavior::getCommentCount($db));
}
我希望从我的$this->mapTable
课程中获得$this->mapCommentColumn
和CommentableBehavior
。有任何想法吗?感谢
我在print_r()
<h1>CException</h1> <p>Property "CommentModule.mapTable" is not defined. (/Library/WebServer/Documents/dev/common/lib/yii/framework/base/CComponent.php:130)</p><pre>#0 /Library/WebServer/Documents/dev/common/lib/yii/framework/base/CModule.php(105): CComponent->__get('mapTable')
答案 0 :(得分:0)
在modules/comment/models/comment.php
put
public function behaviors()
{
return array(
'commentable'=>array(
'class'=>'comment.behaviors.CommentableBehavior',
),
);
}
您可以通过$this->mapTable
或$this->commentable->mapTable