Book Image

CakePHP 2 Application Cookbook - Third Edition

By : Watts
Book Image

CakePHP 2 Application Cookbook - Third Edition

By: Watts

Overview of this book

If you are a CakePHP developer looking to ease the burden of development, then this book is for you. As a headfirst dive into the framework, this collection of recipes will help you get the most out of CakePHP, and get your applications baked in no time. Even if you're not familiar with the framework, we'll take you from basic CRUD building to useful solutions that will aid in getting the job done quickly and efficiently.
Table of Contents (14 chapters)
13
Index

View caching


Caching your views is an important step towards improving the loading time of your application as content is served faster. This can have a noticeable effect on users, as they get to content and features quicker, making them a bit happier.

In this recipe, we'll build an example scenario that shows off some of the base caching features of CakePHP.

Getting ready

First, open your core.php file in app/Config/, make sure the following line is not commented out, and set it to true:

Configure::write('Cache.check', true);

This configuration option enables and generates cached view files for requests.

Also, in your bootstrap.php file in app/Config/, make sure that CacheDispatcher is set in your Dispatcher.filters configuration. Take a look at the following example:

Configure::write('Dispatcher.filters', array(
  'AssetDispatcher',
  'CacheDispatcher'
));

We'll then need a controller to work with. So, create a TimestampsController.php file in app/Controller/, and add the following content:

&lt...