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
Credits
Foreword
About the Authors
About the Reviewer
www.PacktPub.com
Preface
Index

Translations


Offering your content in various languages is an important step many applications face at some point in their life cycle. Fortunately for you, CakePHP comes well prepared for internationalized applications.

In this recipe, we'll look at how to handle translations in your views, showing the various functions available to deal with different scenarios, and provide a simple interface to the framework's I18n class.

Getting ready

For this recipe, we will create ArticlesController to display a list of articles. So, create a file named ArticlesController.php in app/Controller/ with the following content:

<?php
App::uses('AppController', 'Controller');
    
class ArticlesController extends AppController {
}

We'll also need a table of articles, so create one with the following SQL statement:

CREATE TABLE articles (
  id INT NOT NULL AUTO_INCREMENT,
  title VARCHAR(100),
  content TEXT,
  created DATETIME,
  PRIMARY KEY(id)
);

Also, create some articles using the following SQL statement:

INSERT...