public function index()
    {
        //The "render" type can set by query or by cookies
        $render = $this->request->getQuery('render', $this->request->getCookie('render-photos'));

        $query = $this->Photos->find()->contain(['Albums' => ['fields' => ['id', 'slug', 'title']]]);

        $this->paginate['order'] = ['Photos.created' => 'DESC'];

        //Sets the paginate limit and the maximum paginate limit
        //See http://book.cakephp.org/3.0/en/controllers/components/pagination.html#limit-the-maximum-number-of-rows-that-can-be-fetched
        if ($render === 'grid') {
            $this->paginate['limit'] = $this->paginate['maxLimit'] = getConfigOrFail('admin.photos');
            $this->viewBuilder()->setTemplate('index_as_grid');
        }

        $this->set('photos', $this->paginate($this->Photos->queryFromFilter($query, $this->request->getQueryParams())));

        if ($render) {
            $this->response = $this->response->withCookie((new Cookie('render-photos', $render))->withNeverExpire());
        }
    }