display weekdays on the calendar
<p>I am having a problem. I can't display the weekdays.
So when I click next it should display the week for nextweek displaying Monday to Friday.
And when I click previous it should display lastweek Monday to Friday </p>

<p>here's my code</p>

<p>in controller</p>

<pre><code>    &lt;?php
        public function calendar($dt) {
    //         = date("Y/m/d");
            $beginDate = $dt;
            $endDate = date("Y-m-d", strtotime($dt . "+6 days"));

            $posts = $this-&gt;Post-&gt;getWeekPosts($beginDate, $endDate);
            $members = $this-&gt;Post-&gt;PostgetUniqueMembers($posts);
    //        $week = $this-&gt;Post-&gt;weekNo($beginDate, $endDate);

            $this-&gt;set("posts", $posts);
            $this-&gt;set("members", $members);
            $this-&gt;set("begin", $beginDate);
    //        $this-&gt;set("week", $week);
        }


in view

&lt;div id="content"&gt;
        &lt;span id="calendar-week"&gt;
&lt;!--            &lt;h2&gt; week  &lt;?php echo $week; ?&gt; &lt;?php echo date("F Y", strtotime($begin)) ?&gt; &lt;/h2&gt;--&gt;
            &lt;h2&gt; week &lt;?php echo date("F Y", strtotime($begin)) ?&gt; &lt;/h2&gt;
            &lt;a href="/cakemgmt/posts/calendar/&lt;?php echo date("Y-m-d", strtotime($begin . "- 6 days")) ?&gt;"&gt;Previous&lt;/a&gt; | 
            &lt;a href="/cakemgmt/posts/calendar/&lt;?php echo date("Y-m-d", strtotime($begin . "+ 6 days")) ?&gt;"&gt;Next&lt;/a&gt;
        &lt;/span&gt;

        &lt;div id="calendar"&gt;
            &lt;table&gt;

                &lt;tr id="calendar-names"&gt;&lt;!-- member names --&gt;

                    &lt;td&gt;&amp;nbsp;&lt;/td&gt;

                    &lt;?php foreach ($members as $member) { ?&gt;
                        &lt;td&gt;&lt;p&gt;&lt;?php echo $member ?&gt;&lt;/p&gt;&lt;/td&gt;
                    &lt;?php } ?&gt;

                &lt;/tr&gt;

                &lt;?php
                foreach ($posts as $key =&gt; $post) {
                    ?&gt;
                    &lt;tr&gt;
                        &lt;td class="calendar-background-days"&gt;&lt;p class="calendar-days"&gt;&lt;?php echo date("D", strtotime($key)) ?&gt;&lt;/p&gt;&lt;/td&gt;
                        &lt;?php foreach ($members as $memberKey =&gt; $member) { ?&gt;

                            &lt;td class="calendar-background-content"&gt;&amp;nbsp;
                                &lt;?php foreach ($post as $contentKey =&gt; $content) { ?&gt;
                                    &lt;?php if ($contentKey == $memberKey) { ?&gt;
                                        &lt;?php foreach ($content as $c) { ?&gt;
                                            &lt;p&gt;&lt;?php echo $c['Post']['content'] ?&gt;&lt;/p&gt;
                                        &lt;?php } ?&gt;
                                        &lt;?php
                                    }
                                }
                                ?&gt;
                            &lt;/td&gt;
                        &lt;?php } ?&gt;
                    &lt;/tr&gt;
                &lt;?php } ?&gt;

            &lt;/table&gt;
        &lt;/div&gt;

    &lt;/div&gt;
</code></pre>

<p>in model</p>

<pre><code>public function getWeekPosts($begin, $end) {

        $res = $this-&gt;find("all", array("order" =&gt; array('deadline', 'member_id'), "conditions" =&gt; "deadline BETWEEN '" . $begin . "' AND '" . $end . "'"));

        $res = $this-&gt;formatWeekPosts($begin, $res);

        return $res;
    }




public function formatWeekPosts($begin, $res) {
       $dt = array();

        for ($i = 0; $i &lt; 6; $i++) {
            $dt[] = date("Y-m-d", strtotime($begin . "+ " . $i . " days"));
        }

        $members = array();
        $pastMember = "";

        foreach ($res as $r) {
            if ($pastMember != $r['Post']['member_id']) {
                $members[] = $r['Post']['member_id'];
                $pastMember = $r['Post']['member_id'];
            }
        }

       $posts = array();

        foreach ($dt as $d) {
            foreach ($res as $r) {
                if ($r['Post']['deadline'] == $d) {
                    $posts[$d][] = $r;
                }
            }
        }

       $sortedPosts = array();

        foreach ($members as $member) {
            foreach ($posts as $key =&gt; $postDate) {
                foreach ($postDate as $key2 =&gt; $p) {
                    if ($p["Post"]['member_id'] == $member) {
                        $sortedPosts[$key][$p["Post"]['member_id']][$key2] = $p;
                    }
                }
            }
        }
        ksort($sortedPosts);

        return $sortedPosts;
    }



public function PostgetUniqueMembers($posts) {
       $members = array();

        foreach ($posts as $post) {
            foreach ($post as $p) {
                $members[$p[key($p)]["Post"]["member_id"]] = $p[key($p)]["Member"]['username'];
            }
        }
        return $members;
    }
</code></pre>
