public function indexByDate($date)
    {
        //Data can be passed as query string, from a widget
        if ($this->request->getQuery('q')) {
            return $this->redirect([$this->request->getQuery('q')]);
        }

        list($start, $end) = $this->getStartAndEndDate($date);

        $page = $this->request->getQuery('page', 1);

        //Sets the cache name
        $cache = sprintf('index_date_%s_limit_%s_page_%s', md5(serialize([$start, $end])), $this->paginate['limit'], $page);

        //Tries to get data from the cache
        list($posts, $paging) = array_values(Cache::readMany(
            [$cache, sprintf('%s_paging', $cache)],
            $this->Posts->getCacheName()
        ));

        //If the data are not available from the cache
        if (empty($posts) || empty($paging)) {
            $query = $this->Posts->find('active')
                ->find('forIndex')
                ->where([
                    sprintf('%s.created >=', $this->Posts->getAlias()) => $start,
                    sprintf('%s.created <', $this->Posts->getAlias()) => $end,
                ]);
            $posts = $this->paginate($query);

            //Writes on cache
            Cache::writeMany([
                $cache => $posts,
                sprintf('%s_paging', $cache) => $this->request->getParam('paging'),
            ], $this->Posts->getCacheName());
        //Else, sets the paging parameter
        } else {
            $this->request = $this->request->withParam('paging', $paging);
        }

        $this->set(compact('date', 'posts', 'start'));
    }
public function indexByDate($date)
    {
        //Data can be passed as query string, from a widget
        if ($this->request->getQuery('q')) {
            return $this->redirect([$this->request->getQuery('q')]);
        }

        list($start, $end) = $this->getStartAndEndDate($date);

        $page = $this->request->getQuery('page', 1);

        //Sets the cache name
        $cache = sprintf('index_date_%s_limit_%s_page_%s', md5(serialize([$start, $end])), $this->paginate['limit'], $page);

        //Tries to get data from the cache
        list($posts, $paging) = array_values(Cache::readMany(
            [$cache, sprintf('%s_paging', $cache)],
            $this->Posts->getCacheName()
        ));

        //If the data are not available from the cache
        if (empty($posts) || empty($paging)) {
            $query = $this->Posts->find('active')
                ->find('forIndex')
                ->where([
                    sprintf('%s.created >=', $this->Posts->getAlias()) => $start,
                    sprintf('%s.created <', $this->Posts->getAlias()) => $end,
                ]);
            $posts = $this->paginate($query);

            //Writes on cache
            Cache::writeMany([
                $cache => $posts,
                sprintf('%s_paging', $cache) => $this->request->getParam('paging'),
            ], $this->Posts->getCacheName());
        //Else, sets the paging parameter
        } else {
            $this->request = $this->request->withParam('paging', $paging);
        }

        $this->set(compact('date', 'posts', 'start'));
    }
public function indexByDate ( $ date ) { //Data can be passed as query string, from a widget if ( $ this -> request -> getQuery ( 'q' ) ) { return $ this -> redirect ( [ $ this -> request -> getQuery ( 'q' ) ] ) ; } list ( $ start , $ end ) = $ this -> getStartAndEndDate ( $ date ) ; $ page = $ this -> request -> getQuery ( 'page' , 1 ) ; //Sets the cache name $ cache = sprintf ( 'index_date_%s_limit_%s_page_%s' , md5 ( serialize ( [ $ start , $ end ] ) ) , $ this -> paginate [ 'limit' ] , $ page ) ; //Tries to get data from the cache list ( $ posts , $ paging ) = array_values ( Cache :: readMany ( [ $ cache , sprintf ( '%s_paging' , $ cache ) ] , $ this -> Posts -> getCacheName ( ) ) ) ; //If the data are not available from the cache if ( empty ( $ posts ) || empty ( $ paging ) ) { $ query = $ this -> Posts -> find ( 'active' ) -> find ( 'forIndex' ) -> where ( [ sprintf ( '%s.created >=' , $ this -> Posts -> getAlias ( ) ) => $ start , sprintf ( '%s.created <' , $ this -> Posts -> getAlias ( ) ) => $ end , ] ) ; $ posts = $ this -> paginate ( $ query ) ; //Writes on cache Cache :: writeMany ( [ $ cache => $ posts , sprintf ( '%s_paging' , $ cache ) => $ this -> request -> getParam ( 'paging' ) , ] , $ this -> Posts -> getCacheName ( ) ) ; //Else, sets the paging parameter } else { $ this -> request = $ this -> request -> withParam ( 'paging' , $ paging ) ; } $ this -> set ( compact ( 'date' , 'posts' , 'start' ) ) ; }
Lists posts for a specific date.

Month and day are optional and you can also use special keywords `today`
or `yesterday`.

Examples:
<pre>/posts/2016/06/11</pre>
<pre>/posts/2016/06</pre>
<pre>/posts/2016</pre>
<pre>/posts/today</pre>
<pre>/posts/yesterday</pre>
@param string $date Date as `today`, `yesterday`, `YYYY/MM/dd`,
`YYYY/MM` or `YYYY`
@return \Cake\Network\Response|null|void
@use \MeCms\Controller\Traits\GetStartAndEndDateTrait\getStartAndEndDate()
Lists posts for a specific date .