Book Image

CakePHP 2 Application Cookbook - Third Edition

Book Image

CakePHP 2 Application Cookbook - Third Edition

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

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:

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