i have a custom model ApplicationVersion
<?php
class ApplicationVersion extends CModel {
public $id;
public $version;
public $description;
public function __construct($id = null, $version = null, $desc = null) {
$this->id = $id;
$this->version = $version;
$this->description = $desc;
}
public function attributeNames() {
return array('id', 'version', 'description');
}
public function rules() {
return array(
array('id, version, description', 'safe'),
);
}
public function search() {
$rawData = array(
new ApplicationVersion(1, '1.1', 'verzija 1.1'),
new ApplicationVersion(2, '1.2', 'verzija 1.2'),
new ApplicationVersion(3, '2.1', 'verzija 2.1'),
new ApplicationVersion(4, '3.1', 'verzija 3.1'),
new ApplicationVersion(5, '4.1', 'verzija 4.1'),
new ApplicationVersion(6, '5.1', 'verzija 5.1'),
new ApplicationVersion(7, '6.1', 'verzija 6.1'),
new ApplicationVersion(13, '1.13', 'verzija 1.13'),
new ApplicationVersion(8, '7.1', 'verzija 7.1'),
new ApplicationVersion(9, '8.1', 'verzija 8.1'),
new ApplicationVersion(10, '1.19', 'verzija 1.19'),
new ApplicationVersion(11, '1.11', 'verzija 1.11'),
new ApplicationVersion(12, '1.12', 'verzija 1.12'),
new ApplicationVersion(14, '1.14', 'verzija 1.14'),
);
$config = array(
'pagination' => array(
'pageSize' => 10,
),
'sort' => array(
'attributes' => array(
'version', 'description',
),
),
);
return new CArrayDataProvider($rawData, $config);
}
}
?>
function search returns CArrayDataProvider, where i try to sort my data.
i pass provider to the CGridView with
$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
'version',
'description',
),
'htmlOptions' => array('style' => 'width:700px'),
));
when the grid shows, data isn’t sorted
and when i press the column header a messagebox pops up and i get a warning
Parameter 1 to array_multisort() expected to be a reference, value given</p>
<h3>Source File</h3>
<p>
...yii\framework\web\CArrayDataProvider.php(122)</p>
<div class="source">
<pre>
00110: if(empty($directions))
00111: return;
00112: $args=array();
00113: foreach($directions as $name=>$descending)
00114: {
00115: $column=array();
00116: foreach($this->rawData as $index=>$data)
00117: $column[$index]=is_object($data) ? $data->$name : $data[$name];
00118: $args[]=$column;
00119: $args[]=$descending ? SORT_DESC : SORT_ASC;
00120: }
00121: $args[]=&$this->rawData;
<div class="error">00122: call_user_func_array('array_multisort', $args);
</div>00123: }
00124:
00125: /**
00126: * Converts the "ORDER BY" clause into an array representing the sorting directions.
00127: * @param string the "ORDER BY" clause.
00128: * @return array the sorting directions (field name => whether it is descending sort)
00129: */
00130: protected function getSortDirections($order)
00131: {
00132: $segs=explode(',',$order);
00133: $directions=array();
00134: foreach($segs as $seg)
is this a bug or am i doing something wrong?