CakePHP Tutorial Part II- Installing and Creating Your First Project in CakePHP

CakePHP Tutorial Installing and Creating Your First Project in CakePHP

Cake is a framework of PHP and is very powerful. It makes the application more robust and manageable. CakePHP is based on the MVC (Model-View-Controller) software design pattern.

Introduction to the MVC Design Pattern in

The MVC pattern separates the application into three parts, the Model layer, the Controller layer and the View layer. The Model layer is responsible for the data retrieval and conversion to meaningful concept. It implements the business logic and actually interacts with the database. The Controller layer handles the user requests and is the communication medium between the model layer and the view layer. The View layer manages the presentation of the data which has been fetched by the Model layer.

The request cycle of the Cake PHP framework is like:

The request from the client is received by the application and goes to the controller via the dispatcher. The controller in turn sends the request to the model layer. The model layer fetches the data from the database as per the requirement and sends it back to the controller. The controller then sends the final data to the view layer, which arranges it in the correct format to be viewed and sends it to the client.

Steps to develop an application in CakePHP

  • Download and install the WAMP sever on your system.
  •  Download the CakePHP framework and unzip the files to the www directory of your wamp folder.
  •  Rename the file ‘/app/config/database.php.default’ to ‘/app/config/database.php ‘
  •  Configure the ‘file/app/config/database.php’ file and set your database userid and password in the file.
  • Create a database in the MySQL and add the required tables with all the desired columns and specifications.
  •  Start with creating your model classes. For this we save a file in the ‘/app/Model’ folder. The name of the file goes the same as the name of the class. The class extends an AppModel class and the name of the class starts with a capital letter.
class Post extends AppModel {

  • Next we create the controller for the above defined model class. The controller file is saved in the ‘/app/controller’ folder and the name is same as the class name. The name of the controller class is the same as the model class in the plural form and followed by the keyword Controller. It extends the class AppController.
class PostsController extends AppController {

  •  Finally we create a view for the above model and controller files. The view file is saved to the ‘/app/View’ folder inside a folder named after the controller class. The view file consists of the html and styling script.

Adding different action functions to the controller and creating views for the same will add functionality to our application.

Please click if you are looking for a tutorial to create a complete application in CakePHP.

Leave a Reply

You must be logged in to post a comment.

Copy link