O'Reilly logo

CakePHP 2 Application Cookbook by Jorge González, James Watts

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Import parser

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.

Getting ready

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required