Top Interview Questions and Answers

Top Interview Questions and Answers
Interview Sortout

Browsing "Older Posts"

Browsing Category "CakePHP"

CakePHP Advance : Most Common Interview Questions and Answers

By Dhananjay → September 6, 2018
cakephp

What is HMAC?
HMAC means Hash-based Message Authentication Code . This is a authentication code used with combination of an encryption key and a hash function.


What is Asset.cacheTime ?
Asset.cacheTime sets the asset cache time. This determines the http header Cache-Control’s max-age, and the http header’s Expire’s time for assets.


What is DSN?
DSN is Data Source Name. A connection string format that is formed like a URI. CakePHP supports DSN’s for Cache, Database, Log and Email connections.

What is PaaS?
Platform as a Service. Platform as a Service providers will provide cloud based hosting, database and caching resources. Some popular providers include Heroku, EngineYard and PagodaBox.

How we can use Cache in CakePHP?
Caching in CakePHP is facilitated by the Cache class. This class provides a static interface and uniform API to interact with various Caching implementations.


What types of Caching Engine does CakePHP provide?
1-FileCache-uses files.
2-ApcuEngine - uses the PHP APCu extension.
3-Wincache - uses the Wincache extension.
4-MemcachedEngine - uses the Memcached extension.
5-RedisEngine - uses the phpredis extension.


What is the default cache file path?
Path to where cache files should be saved. Defaults path is system's temp dir.

How to read a Cache Object in CakePHP?
Using Cache class we can read the object as given below:

$posts=Cache::read('posts');



How to write a Cache Object in CakePHP?
Using Cache class we can write the object as given below:

    Cache::write('posts',$posts);


How to remove an object completely from Cache?
Using Cache class we can delete the object as given below:

    Cache::delete('posts');


Can we read,write and delete multiple objects at a time?
Yes , we can do cache operations on multiple objects using functions like:

    Cache::deleteMany(['posts','comments','users']);
    Cache::readMany(['posts','comments','users']);
    Cache::writeMany(['posts'=>$posts,'comments'=>$comments,'users'=>$users]);


What is difference between Cache:clear() and Cache::delete() ?
Cache:clear() removes the values from associated with keys and empty them to hold new values, where as Cache:delete() removes the object completely from cache.

How can we disable or enable cache glaoblly in CakePHP?
We don't need to disable all Cache read & writes and to expiration. We can do this using enable() and disable():

    Cache::disable();
    Cache::enable();


What are the different log levels in CakePHP?
1-Emergency: system is unusable
2-Alert: action must be taken immediately
3-Critical: critical conditions
4-Error: error conditions
5-Warning: warning conditions
6-Notice: normal but significant condition
7-Info: informational messages
8-Debug: debug-level messages


What is CakeRequest?
CakeRequest is the default request object used in CakePHP. By default, CakeRequest is assigned to $this->request, and is available in Controllers, Views and Helpers.


What are different ways to access the parameters in CakePHP?
Following ways :

$this->request->controller;
$this->request['controller'];
$this->request->params['controller'];


How can we access the Passed Argumets from URI in CakePHP?
Way to access the Passed Argumets in CakePHP as:

$this->request->pass;
$this->request['pass'];
$this->request->params['pass'];


How can we access the Named Parameters from URI in CakePHP?
Way to access the Named Parameters in CakePHP as:

$this->request->named;
$this->request['named'];
$this->request->params['named'];


How can we read Query String Parameters?
We can read these paameters using Cake Request Handler :

  // url is as : /posts/index?page=1&sort=title
  $this->request->query['page'];


How can we detect the request type?
We can check any request as :
$this->request->is('post');
$this->request->is('get');
$this->request->is('ajax');
$this->request->is(['put','post']);


How to detect environment in CakePHP?
$this->request->addDetector(
    'post',
    array('env' => 'REQUEST_METHOD', 'value' => 'POST')
);


How to detect pattern value in CakePHP?
$this->request->addDetector(
    'iphone',
    array('env' => 'HTTP_USER_AGENT', 'pattern' => '/iPhone/i')
);


How to detect options in CakePHP?
$this->request->addDetector('internalIp', array(
    'env' => 'CLIENT_IP',
    'options' => array('192.168.0.101', '192.168.0.100')
));


How to detect callback in CakePHP?
$this->request->addDetector(
    'awesome',
    array('callback' => function ($request) {
        return isset($request->awesome);
    })
);



How to find the root directory of the the application?
$this->request->webroot;

How to find the base path in CakePHP?
$this->request->base;

How to find the full address of the current request in CakePHP?
$this->request->here;

CakePHP Advance Interview Questions and Answers For Experienced and Freshers

By Dhananjay → 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.

CakePHP Interview Questions and Answers

By Dhananjay → July 1, 2018

What is CakePHP ?
CakePHP is an open-source free web framework based on MVC pattern and written in PHP scripting Language for rapid web development.

What is MVC in CakePHP?
Model view controller (MVC) is an architectural pattern used in software engineering.
Model: Handle database related functionality, manipulating database related query like add, edit , delete.
View: Design parts written here (HTML+PHP)
Controller: Business Logic goes here

What are controllers?
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.


List some features of CakePHP framework ?
Top features of CakePHP framework
1-MVC Architecture
2-Zero configuration
3-Inbuilt validation
4-ACL Functionality and Security
5-CRUD scaffolding
6-Easily extendable with plug-ins
7-Quick and flexible


What are Hooks in CakePHP?
CakePHP hooks are callback functions that are called before or after a model operation and defined in models.
List of some Hooks functions provided by CakePHP.
1-beforeFind
2-afterFind
3-beforeValidate
4-afterValidate
5-beforeSave
6-afterSave
7-beforeDelete
8-afterDelete
9-onError


What is default function for a controller?
function index() is default function in controller.

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

What Is Scaffolding In Cakephp?
Scaffolding is a technical way that allows a developer to define and create a basic application that can create, retrieve, update and delete objects.

How To Get Current URL In CakePHP?
Simple using the following bit of code:
 
  $this->here;
 

How can you make urls search engine friendly while using cakephp?
It’s an automatic task that is done by cakephp.

How cakephp URL looks in address bar?
http://example.com/controller/action/param1/param2/param3

What is Composer? How to create a CakePHP Project using Composer?
Composer is a tool for managing project dependencies. You can create a CakePHP project using Composer by running below commands on terminal.

 
  php composer.phar create-project --prefer-dist cakephp/app my_app_name
 

How To Get Controller Name In CakePHP Views?
Get controller name in CakePHP:
 
  $this->request->params['controller'];
 


What is a Helper in CakePHP?
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.


What are are drawbacks of cakephp?.
The learning curve, and it loads full application before it starts your task. Its not recommended for small projects because of heavy structure.


What is the name of Cakephp database configuration file name and its location?
Default file name is database.php.default.
Its located in "/app/config/database.php.defaut"


What is habtm?
Has And Belongs To Many is a kind of associations that can be defined in models for retrieving associated data across different entities.

List some database related functions in cakephp.
find, findAll , findAllBy , findBy , findNeighbours and query.