-
Book Overview & Buying
-
Table Of Contents
CakePHP 2 Application Cookbook - Third Edition
By :
One benefit of using shells in CakePHP is to handle process-intensive tasks, which take a long time to run. In this recipe, we'll create a CakePHP console shell to deal with a mass CSV data import. We'll process a data file and import all rows, while logging import errors to another file.
As this is the only task in our shell, we're not using Task this time.
First, if you don't have it already, create the packages database table using the following SQL statement:
CREATE TABLE packages ( id INT NOT NULL AUTO_INCREMENT, recipient VARCHAR(255) NOT NULL, address VARCHAR(255) NOT NULL, created DATETIME, modified DATETIME, PRIMARY KEY(id) );
Then, create the associated model in a file named Package.php in app/Model/ with the following content:
<?php
App::uses('AppModel', 'Model');
class Package extends AppModel {
}Perform the following steps:
Create a file named ImportShell.php in app/Console/Command/ to import CSV files with the following code...
Change the font size
Change margin width
Change background colour