Book Image

CakePHP 2 Application Cookbook

By : James Watts, Cake Software Foundation, Inc.
Book Image

CakePHP 2 Application Cookbook

By: James Watts, Cake Software Foundation, Inc.

Overview of this book

Table of Contents (20 chapters)
CakePHP 2 Application Cookbook
About the Authors
About the Reviewer

Console API

CakePHP provides a rich console API to let you create and reuse specific project tasks that are more suited to being executed in a console environment. Keep in mind that when running commands from shell, you're not restricted by the same limitations the web server typically puts on server resources such as memory use and execution time. You can also have a less restrictive PHP configuration for your CLI environment, allow additional PHP extensions, and do more.

In this recipe, we'll create a new console shell and task to explore some of the features of the console shell API. Note that we'll be using a shell named PdfShell as an example, but no real PDF generation will happen.

How to do it...

Perform the following steps:

  1. First, update our existing file named PdfShell.php in app/Console/Command/ with the following content:

    App::uses('AppShell', 'Console/Command');
    class PdfShell extends AppShell {
      public $tasks = array('Generate');
      public function main() {