What is the default cache Engine in CakePHP?
File Engine is the default cache Engine in Cake PHP.
What are the cache engines that CakePHP support?
Different type of cache engine supported by Cake PHP:
- File
- APC
- Win
- Xcache
- Memcache
- Redis
How many type of Associations are there in CakePHP Models?
There are four association types in CakePHP:
- One to One – hasOne e.g. A user has one profile.
- One to Many – hasMany e.g. A user can have multiple recipes.
- Many to One – belongsTo e.g. Many recipes belong to a user.
- Many to Many hasAndBelongsToMany e.g. Recipes have, and belong to, many ingredients.
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' )); }
How to create Pagination in List view?
Cake PHP has a built in component ‘Paginator’. We can use this Component to create Pagination.
How to destroy an association?
Use ‘unbindModel‘ to destroy a particular type of association.
$this->Leader->unbindModel( array('hasMany' => array('Follower')) );
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);
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;
What is layout in CakePHP?
View files that contain representational code that wraps many interfaces in your application. Most views are rendered inside a layout.
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.
What are most used Components in CakePHP?
There may be unlimited number of component in a PHP project. Few components are already there in CakePHP and they are frequently and commonly used components. We have listed few such components:-
- Security
- Sessions
- Access control lists
- Emails
- Cookies
- Authentication
- Request handling
- Scaffolding
What Is A Behavior?
Behavior in CakePHP is associated with Models. Behaviour is used to change the way models behaves and enforcing model to act as something else.