CakePHP Advance Interview Questions and Answers For Experienced and Freshers

By Dhananjay yadav August 25, 2018

(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:
1-FileCache
2-ApcCache
3-Wincache
4-XcacheEngine
5-MemcacheEngine
6-RedisEngine

(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.
$this->Leader->unbindModel(
        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(
            'Channel.id = 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->layout='';
$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?
1-Security
2-Sessions
3-Access control lists
4-Emails
5-Cookies
6-Authentication
7-Request handling
8-Scaffolding

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

No Comment to " CakePHP Advance Interview Questions and Answers For Experienced and Freshers "