我正在尝试使用输入日期使用动态列渲染Cgridview(列从from_dt动态开始到to_date),
现在我想为动态列提供Chtml :: link但我收到错误undefined index : "01" (dynamic columns ).
$columns =array(array('name'=>'Agents', 'header'=>'Agents',
'htmlOptions'=>array('style'=>'width: 300px')),
array('name'=>'category', 'cssClassExpression' => '$data["category"]== "Total" ? "Total" :($data["postcode"] != "" ? "Sub" :$data["category"] )' ,'header'=>'Category','htmlOptions'=>array('style'=>'width: 300px;')),
array('name'=>'postcode', 'header'=>'PostCode','htmlOptions'=>array('style'=>'width: 350px')),
array('name'=>'TotalPeriod', 'header'=>'TotalPeriod'),
array('name'=>'percent', 'header'=>'%','htmlOptions'=>array('style'=>'width: 350px')),
);
//Dynamic Column Rendering code
for($i=0;$i < $numberDays ; $i++)
{
if ($i != 0)
$start = date('d-m-Y', strtotime("+1 day", strtotime($start)));
$timestamp = strtotime($start);
$columns[] = array('name'=>date("d", $timestamp), 'header'=>date("d", $timestamp), 'value' =>'CHtml::link($data[date("d", '.$timestamp.')],"http://www.google.com",array("target"=>"_blank"))', 'type' => 'raw',);
}
答案 0 :(得分:3)
请检查以下工作代码,
for($i=0;$i < $numberDays ; $i++)
{
if ($i != 0)
$start = date('Y-m-d', strtotime("+1 day", strtotime($start)));
$timestamp = strtotime($start);
$day = date("d", $timestamp);
$columns[] = array('name'=>date("d", $timestamp), 'header'=>date("d", $timestamp), 'value' =>'getVal($data,"'.$day.'") > 0 ? CHtml::link(getVal($data,"'.$day.'")," ",array("class"=>"drillDay","id"=>"'.$start.'")) : getVal($data,"'.$day.'")', 'type' => 'raw');
//$columns[] = date("d", $timestamp);
//$datatemp[$start] = $start;
}