100 TOP CakePHP Interview Questions and Answers [UPDATED]

If you’re looking for CakePHP Questions and whether you’re experienced or fresher & don’t know what kind of questions will be asked in CakePHP job interview, then go through the below Real Time 100 Top CakePHP Interview Questions and Answers to crack your job interview.

CakePHP Interview Questions and Answers

  • Question:What Is A Helper?

    Answer :

    Helpers in CakePHP are associated with Presentation layers of application.Helpers mainly contain presentational logic which is available to share between many views, elements, or layouts.

  • Question:What Is The Current Stable Version Of Cakephp?

    Answer :

    3.0 (on date 2015-06-12).

  • Question:How Can You Include A Javascript Menu Throughout The Site. Give Steps.

    Answer :

    By adding the javascript files in webroot and call them in default views if needed everywhere or just in the related veiws.

  • Question:What Are Commonly Used Components Of Cakephp?

    Answer :

    1. Security
    2. Sessions
    3. Access control lists
    4. Emails
    5. Cookies
    6. Authentication
    7. Request handling
    8. Scaffolding
  • Question:What Is A Component In Cakephp?

    Answer :

    Components are packages of logic that are shared between controllers. They are useful when a common logic or code is required between different controllers.

  • Question:What Are The Advantages Of Each?which Would You Use And Why?

    Answer :

    An advantage with first case $this->set(‘posts’, $posts); is that it allows two different names for the view file and controller file. For example, you could write something like $this->set(‘postData’, $posts);. Now the variable name in the view file would be $postData.

    The advantage with the second approach $this->set(compact()); is easier to write, and useful especially when we are setting several variables to the view.No need to add separate line for each variable as we have with $this->set();

    For example,


  • Question:What Is The Naming Convention In Cakephp?

    Answer :

    Table names are plural and lowercased,model names are singular and CamelCased: ModelName, model filenames are singular and underscored: model_name.php, controller names are plural and CamelCased with *Controller* appended: ControllerNamesController, controller filenames are plural and underscored with *controller* appended: controller_names_controller.php.

  • Question:Server Requirements For Cakephp?

    Answer :

    Here are the requirements for setting up a server to run CakePHP:

    • An HTTP server (like Apache) with the following enabled: sessions, mod_rewrite (not absolutely necessary but preferred)
    • PHP 4.3.2 or greater. Yes, CakePHP works great in either PHP 4 or 5.
    • A database engine (right now, there is support for MySQL 4+, PostgreSQL and a wrapper for ADODB).
  • Question:What Are Commonly Used Helpers Of Cakephp?

    Answer :

    • FormHelper
    • HtmlHelper
    • JsHelper
    • CacheHelper
    • NumberHelper
    • Paginator
    • RSS
    • SessionHelper
    • TextHelper
    • TimeHelper
  • Question:What Is The Name Of Cakephp Database Configuration File Name And Its Location?

    Answer :

    Default file name is database.php.default.

    Its located at “/app/config/database.php.default”.To connect with database it should be renamed to database.php

  • Question:Why Cakephp Have Two Vendor Folder?what Is The Difference Between Two Vendors Folder Available In Cakephp?

    Answer :

    There will be two vendor folders available in cakephp frame work.

    one in ” app ” folder and one in root folder

    The vendor folder in the app folder is used to place the third-party libraries which are application specific.

    The vendor folder in the root folder is used to place the third-party libraries which are used for multiple applications.

  • Question:What Is The First File That Gets Loaded When You Run A Application Using Cakephp?can You Change That File?

    Answer :


    yes it can be changed.Either through index.php , or through .htaccess

  • Question:What Is Cakephp Request Cycle?

    Answer :

    A typical CakePHP request cycle starts with a user requesting a page or resource in your application. At a high level, each request goes through the following steps −

    • The webserver rewrite rules direct the request to webroot/index.php.
    • Your application’s autoloader and bootstrap files are executed.
    • Any dispatch filters that are configured can handle the request, and optionally generate a response.
    • The dispatcher selects the appropriate controller & action based on routing rules.
    • The controller’s action is called and the controller interacts with the required Models and Components.
    • The controller delegates response creation to the View to generate the output resulting from the model data.
    • The view uses Helpers and Cells to generate the response body and headers.
    • The response is sent back to the client.
  • Question:What Is Recursive In Cakephp?

    Answer :

    To understand this topic follow this post :

    Recursive in cakephp

  • Question:Which Function Is Executed Before Every Action In The Controller?

    Answer :

    function beforeFilter()

  • Question:What Is A Behavior?

    Answer :

    Behaviors in CakePHP are associated with Models.Behaviors are used to change the way models behaves and enforcing model to act as something else.

  • Question:What Is Default Function For A Controller?

    Answer :

    index() function

  • Question:What Is A Layout?

    Answer :

    Layout in cakephp are used to display the views that contain presentational code. In simple views are rendered inside a layout.

  • Question:What Is Habtm?

    Answer :

    Has and belongs to many is a kind of associations that can be defined in models for retrieving associated data across different entities.

  • Question:What Are Controllers?

    Answer :

    A controller is used to manage the logic for a part of your application. Most commonly, controllers are used to manage the logic for a single model. Controllers can include any number of methods which are usually referred to as actions. Actions are controller methods used to display views. An action is a single method of a controller.

  • Question:How To Include Helpers In Controller ?

    Answer :

    public $helpers = array(‘Form’, ‘Html’, ‘Js’, ‘Time’);

    to in specific action use below code in that action

    $this->helper[] =”helper_name”;

  • Question:Using Cakephp, What All Are Drawbacks?

    Answer :

    It loads full application before it starts your task. It’s not recommended for small projects because of its resource-heavy structure.

  • Question:How To Set Layout In The Controller?

    Answer :

    var $layout = ‘layout_name’;

    to overwrite for a specific action use below code in that action

    $this->layout =”layout_name”;

  • Question:What Is Wrong With The Below Validation Rule?

    Answer :

    ’email’ => array(
        ‘rule’ => array(
            ‘rule’ => ‘notEmpty’,
            ‘message’ => ‘Please Enter Email address.’
        ‘rule’ => array(
            ‘rule’ => ’email’,
            ‘message’ => ‘Entered Email address is invalid.’

    The problem is the first rule notEmpty will never be called because email rule will overwrite it.While using multiple validation rules for the same field you must keep the rule key “unique”. In this case if we want to use multiple rules then, we can simple change the rule key names like,

    ’email’ => array(
        ‘rule1’ => array(
            ‘rule’ => ‘notEmpty’,
            ‘message’ => ‘Please Enter Email address.’
        ‘rule2’ => array(
            ‘rule’ => ’email’,
            ‘message’ => ‘Entered Email address is invalid.’

  • Question:How To Write, Read And Delete The Session In Cakephp?

    Answer :

    $this->Session->write(‘Bird.Color’, ‘Black’);
    $black = $this->Session->read(‘Bird.Color’);

  • Question:List Some Of The Features In Cakephp?

    Answer :

    1. Compatible with versions 4 and 5 of PHP
    2. MVC architecture
    3. Built-in validations
    4. Caching
    5. Scaffolding
    6. Access Control Lists and Authentication.
    7. CSRF protection via Security Component.
  • Question:What Is The Difference Between Component, Helper, Behavior?

    Answer :

    Component is a Controller extension, Helpers are View extensions, Behavior is a Model Extension.

  • Question:What Is Scaffolding In Cakephp?

    Answer :

    Scaffolding is a technique that allows a developer to define and create a basic application that can create, retrieve, update and delete objects.

  • Question:What Is The Use Of $this->set(compact());?

    Answer :

    Using $this->set(compact()) , we can pass multiple parameters to access into the view file.

    For example,


    Now all these variables will be available in respective view file.

  • Question:How To Add Scaffolding In Your Application?

    Answer :

    To add scaffolding to your application,just add the $scaffold variable in the controller,

    class PostsController extends AppController {
        var $scaffold;

    Assuming you’ve created Post model class file (in /app/Model/post.php).

  • Question:What Is Email Configuration In Cakephp?

    Answer :

    Email can be configured in file config/app.php. It is not required to define email configuration in config/app.php. Email can be used without it; just use the respective methods to set all configurations separately or load an array of configs. Configuration for Email defaults is created using config() and configTransport().

  • Question:How Can We Use Ajax In Cakephp?

    Answer :

    By calling ajax helper and then using it in controller for rendering.

  • Question:What Is The Default Extension Of View Files In Cakephp?can We Change It?if Yes Then How?

    Answer :

    default extension of view files is ‘.ctp’.

    yes we can change it by writing public $ext = ‘.yourext’; in AppController.If you want to change it for particular controller then add it into that controller only.You can also change it for the specific action of the controller by putting it in that action of controller.

    public $ext = ‘.yourext’; in AppController

     – you can change all the views extentions.

     public $ext = ‘.yourext’;  in specific controller like, PostsController

    – you can change all the views extentions of PostsController.

    public $ext = ‘.yourext’;  in specific controller action like, index()

    – you can change the view extention of index.ctp 

    Note: You cannot specify multiple extensions, however it seems like there is a fall back to .ctp if no .php file is found.

  • Question:What Is The Folder Structure Of Cakephp?

    Answer :


  • Question:What Is The Use Of $this->set();

    Answer :

    The set() method is used for creating a variable in the view file.Say for example if we write,

    $this->set(‘posts’,$posts); in controller fie, then the variable $posts will be available to use in the view template file for that action.

  • Question:What Is The Use Of Security.salt And Security.cipherseed In Cakephp? How To Change Its Default Value?

    Answer :

    • The Security.salt is used for generating hashes.we can change the default Security.salt value in /app/Config/core.php.  
    • The Security.cipherseed is used for encrypt/decrypt strings.We can change the default Security.cipherSeed value by editing /app/Config/core.php. 
  • Question:What Is Cakephp?

    Answer :

    CakePHP is a free, open-source, rapid development framework for PHP. It’s a foundational structure for programmers to create web applications. CakePHP goal is to enable developers to work in a structured and rapid manner–without loss of flexibility. CakePHP takes the monotony out of web development.

  • Question:How To Display The Schema Of The Model?

    Answer :

    If you want to display the schema of particular model then you just need to add the following single line of code.For example we have “Posts” Controller.


  • Question:When Cakephp Was Developed?

    Answer :

    CakePHP started in April 2005.When a Polish programmer Michal Tatarynowicz wrote a minimal version of a Rapid Application Framework in PHP, dubbing it Cake.CakePHP version 1.0 released in May 2006.

  • Question:Is It Possible To Have Multiple Validation Rules Per Field In Cakephp?

    Answer :

    Yes its possible.

  • Question:What Is Mvc In Cakephp?

    Answer :

    Model view controller (MVC) is an architectural pattern used in software engineering.

    Model      : Database functions exist in the model
    View        : Design parts written here
    Controller : Business Logic goes here

  • Question:How To Include Components In Controller ?

    Answer :

    public $components = array(‘Emails’, ‘ImageUploader’, ‘Sms’);

  • Question:Which Methods Are Used To Create And Destroy Model Associations On The Fly?

    Answer :

    The bindModel() and unbindModel() Model methods are used to create and destroy model associations on the fly.

  • Question:What Is The Use Of Requestaction Method?

    Answer :

    The method requestAction is used to call a controller’s action from any location and returns data from the action.

  • Question:How Can You Make Urls Search Engine Friendly While Using Cakephp?

    Answer :

    It’s an automatic task that is done by cakephp.

  • Question:What Is A Element?

    Answer :

    Element in cakephp are smaller and reusable bits of view code. Elements are usually rendered inside views.

  • Question:How To Install Cakephp?

    Answer :

    step1: Go to cakephp.org and download the latest version of cakephp.

    step2: Cakephp comes in a .zip file,so unzip it.

    step3: Extract the files in the localhost in the desired folder (for example:cakephp).

    step4: Open the browser and run the URL localhost/cakephp

    step5: Just Follow the instructions display on the page.

  • Question:Can You List Some Database Related Functions In Cakephp?

    Answer :

    find, findAll , findAllBy , findBy , findNeighbours and query.

  • Question:How To Get Current Url In Cakephp?

    Answer :

    To get current url in cakephp use, 

    echo Router::url($this->here, true);

    This will give full URL with hostname.If you want to get relative path instead of full URL,then use the following code:

    echo $this->here;

    This will produce absolute URL excluding hostname i.e. /controller/abc/xyz/

  • Question:How Can You Set Custom Page Title For The Static Page?

    Answer :

    To set a custom page title, copy-paste following code anywhere in your static page (.ctp) file:

    $this->set(“title_for_layout”, “My page title”);