使用codeigniter日历类通过generate方法传递数组进行查看

时间:2014-04-27 09:30:17

标签: php codeigniter calendar

最近,我正在使用Codeigniter的Calendar库。我想将以下数组传递给$this->calendar->generate();

数组如下 -

Array
(
    [0] => Array
        (
            [username] => Altab Hossen
            [branch_name] => Branch 1
            [working_date] => 2014-04-16
            [time_in] => 06:13:05
            [time_out] => 09:57:11
            [hours] => 3.7350
        )

    [1] => Array
        (
            [username] => Altab Hossen
            [branch_name] => Branch 1
            [working_date] => 2014-04-25
            [time_in] => 14:42:22
            [time_out] => 22:42:31
            [hours] => 8.0025
        )

)
控制器中的

- 我尝试过如下

$data['calview'] = $this->calendar->generate($arrayVariable);
$this->load->view('calendarview');

在视图中

echo $calview;

1 个答案:

答案 0 :(得分:0)

日历库does not support passing multiple content data到一天。它实际上期望a link as the content of the day。如果你要为每一天生成一个字符串(可以包含HTML),你可以按照以下方式调用日历:

$year = 2014;  // Change me
$month = 6;    // Change me
$arrayVariable = array(6 => "Altab Hossen from Branch 1 came in at 06:13:05 and left at 09:57:11 for a total of 3.37350 hours");
$data['calview'] = $this->calendar->generate($year, $month, $arrayVariable);

在日历的模板中,您还必须更改:

{cal_cell_content}<a href="{content}">{day}</a>{/cal_cell_content}
{cal_cell_content_today}<div class="highlight"><a href="{content}">{day}</a></div>{/cal_cell_content_today}

类似

{cal_cell_content}<h3>{day}</h3><p>{content}</p>{/cal_cell_content}
{cal_cell_content_today}<h3>{day}</h3><div class="highlight">{content}</div>{/cal_cell_content_today}

如果您希望每天支持多个内容数据,则必须扩展日历类并自行实现。我真的认为最简单的解决方案是提供一个内部包含HTML的字符串内容。它不是最干净的,但它最有可能减少的努力&#34;路由。