CakePHP Advance Interview Questions and Answers For Experienced and Freshers

(1). What is the default cache Engine in CakePHP?
File Engine is the default cache Engine in Cake PHP.

(2). How many types of cache does CakePHP Support?
Different types of cache supported by CakePHP:

(3). How mamy types of Associations are there in CakePHP Models?
There are four association types in CakePHP:
Relationship Association type Example
one to one hasOne A user has one profile.
one to many hasMany A user can have multiple recipes.
many to one belongsTo Many recipes belong to a user.
many to many hasAndBelongsToMany Recipes have, and belong to, many ingredients.

(4). How to create association?
Model association example:

class Toy extends AppModel {
    public $hasOne = 'Profile';
    public $hasMany = array(
        'Toy' => array(
            'className' => 'Toy',
            'conditions' => array('Toy.approved' => '1'),
            'order' => 'Toy.created DESC'

(5). How to create Pagination in List view?
Cake PHP has a built in component ‘Paginator’. We can use this Component to create Pagination.

(6). How to destroy an association?
Use ‘unbindModel’ to destroy a particular type of association.

        array('hasMany' => array('Follower'))

(7). Give an example of LEFT JOIN using CakePHP ORM?
LEFT JOIN example using cake php ORM:

$options['joins'] = array(
    array('table' => 'channels',
        'alias' => 'Channel',
        'type' => 'LEFT',
        'conditions' => array(
            ' = Item.channel_id',
$Item->find('all', $options);

(8). How to prevent the default View and Layout to be rendered?
We can set the default view and default Layout variable to false.

$this->autoRender = false;

(9). What is layout in CakePHP?
View files that contain presentational code that wraps many interfaces in your application. Most views are rendered inside a layout.

(10).  What Is A Component In Cakephp?
Components are packages shared between controllers. They are useful when a common logic or code is required between different controllers.

(11). What are Components Used in Cakephp?
3-Access control lists
7-Request handling

(12). What Is A Behavior?
Behaviors in CakePHP are associated with Models.Behaviors are used to change the way models behaves and enforcing model to act as something else.

Spread the love