CakePHP Advance : Most Common Interview Questions and Answers

By Dhananjay yadav 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;

No Comment to " CakePHP Advance : Most Common Interview Questions and Answers "