Book Image

CakePHP 2 Application Cookbook - Third Edition

By : Watts
Book Image

CakePHP 2 Application Cookbook - Third Edition

By: Watts

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

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