【问题标题】:Chtml link for Dynamic columns in Cgridview - Yii FrameworkCgridview 中动态列的 Chtml 链接 - Yii 框架
【发布时间】:2014-06-26 17:27:19
【问题描述】:

我正在尝试使用输入日期(动态列从 from_dt 到 to_date 开始)呈现具有动态列的 Cgridview,

现在我想为动态列提供 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',);

    } 

【问题讨论】:

    标签: php yii cgridview yii-chtml


    【解决方案1】:

    请检查下面的工作代码,

    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;
        } 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-08-29
      • 2013-12-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多