Yii CList错误-没有名为“的方法或闭包”;setReadOnly";

Yii CList错误-没有名为“的方法或闭包”;setReadOnly";,yii,frameworks,clist,Yii,Frameworks,Clist,我有一个使用CList的基本函数-出于某种原因,我得到以下错误: CList and its behaviors do not have a method or closure named "setReadOnly". 我的php代码 $list = new CList(array('python', 'ruby')); $anotherList = new Clist(array('php')); var_dump($list); $list->mergeWith($anoth

我有一个使用CList的基本函数-出于某种原因,我得到以下错误:

CList and its behaviors do not have a method or closure named "setReadOnly".
我的php代码

$list = new CList(array('python', 'ruby'));
$anotherList = new Clist(array('php'));
    var_dump($list);
$list->mergeWith($anotherList);
    var_dump($list);
$list->setReadOnly(true); // CList and its behaviors do not have a method or closure named "setReadOnly". 
有人能解释我为什么会犯这个错误吗

我直接从Yii最近的一本书中复制了这段代码。。。所以我有点困惑

//更新:在mergeWith()之前和之后添加了var_转储


CList方法setReadOnly()受保护,因此不能从正在使用的范围中调用,只能从其本身或继承类中调用。看

但是,CList类允许在其构造函数中将列表设置为只读

public function __construct($data=null,$readOnly=false)
{
    if($data!==null)
    $this->copyFrom($data);
    $this->setReadOnly($readOnly);
}
所以

导致错误

CException The list is read only. 
我不确定这是否是你想要的结果,但如果你想要一个只读的CList,这是一种获得它的方法

您可能会认为,在合并后续clist时,可以在末尾将readonly设置为true,但是mergeWith()只合并_d数据数组,而不合并其他类变量,因此它仍然为false

$list = new CList(array('python', 'ruby'));
$anotherList = new CList(array('php'));
$yetAnotherList = new CList(array('javacript'), true);

$list->mergeWith($anotherList);
$list->mergeWith($yetAnotherList);

var_dump($list); // ["_r":"CList":private]=>bool(false)

您是否尝试打印($list);要检查clist,请使用readonly变量。在mergewith()函数readOnly是公共成员,但被继承。我在调用之前和之后添加了列表变量的var\u dump。无论如何,这个问题很奇怪,很奇怪。。这并不重要,我只是在玩Yii中的一些“较小”功能,我还没有遇到过。。。但我同意这很奇怪:)
CException The list is read only. 
$list = new CList(array('python', 'ruby'));
$anotherList = new CList(array('php'));
$yetAnotherList = new CList(array('javacript'), true);

$list->mergeWith($anotherList);
$list->mergeWith($yetAnotherList);

var_dump($list); // ["_r":"CList":private]=>bool(false)