php - Cgridview 中动态列的 Chtml 链接 - Yii Framework

标签 php yii cgridview yii-chtml

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

现在我想为动态列提供 Chtml::link,但我收到错误 undefined index :“01”(动态列)。

$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',);

    } 

enter image description here

最佳答案

请检查下面的工作代码,

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

关于php - Cgridview 中动态列的 Chtml 链接 - Yii Framework,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23556712/

相关文章:

Javascript 与 PHP——框架与库

php - 在yii中为Cgridview设置css

php - CGridView 自定义列过滤器

php - 如何增加容器宽度以修复 yii2 中的 GridView 滚动

php - 尝试将 MysQl Timestamp 转换为 Time Ago 时无法解析时间字符串

java - 使用 <a> 标签在 jsp 页面中链接 php 页面

php - 如何在 Yii 中保存数据并确保正确保存?

.htaccess - Yii 如何获得干净漂亮的 URL

php - 如何在 Yii 2 中删除多行

php - 从 python 销毁 session ,执行 php 脚本