无脂框架:如何使用Matrix类显示日历?

时间:2015-07-10 14:41:46

标签: fat-free-framework

$matrix = \Matrix::instance();
$cal = $matrix->calendar('2014-06', 1);

我无法弄清楚如何在$cal&让它在视图中显示

1 个答案:

答案 0 :(得分:0)

calendar()方法返回一个数周的数组。

这是一个基本的例子:

<强>的index.php

$f3=require('lib/base.php');

$f3->route('GET /cal/@year/@month',function($f3,$params){
  $f3->cal=Matrix::instance()->calendar($params['year'].'-'.$params['month'],1);
  $f3->title=date('F Y',mktime(0,0,0,$params['month'],1,$params['year']));
  echo Template::instance()->render('cal.html');

});

$f3->run();

<强> cal.html

<h1>{{ @title }}</h1>
<table>
    <thead>
        <tr>
            <th>Mo</th>
            <th>Tu</th>
            <th>We</th>
            <th>Th</th>
            <th>Fr</th>
            <th>Sa</th>
            <th>Su</th>
        </tr>
    </thead>
    <tbody>
        <repeat group="@cal" value="@week">
            <tr>
                <loop from="$d=0" to="$d<7" step="$d++">
                    <td>{{ @@week[ @d ] }}</td>
                </loop>
            </tr>
        </repeat>
    </tbody>
</table>

现在GET /cal/2014/06应该返回类似的内容:

Calendar June 2014