CakePHP is a popular framework which provide rapid development platform for web applications and API.
In this section you will find the advance interview questions based on Cake PHP and these questions are very useful for intermediate level role.
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.
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 type of Caching Engines can be used in CakePHP?
CakePHP provide supports for many types of cache engines.
Cache boost the speed and performance of application. Here is the list of few engines:
- File Cache – uses files.
- APCu Engine – uses the PHP apcu extension.
- Win cache – uses the wincache extension.
- Memcached Engine – uses the Memcached extension.
- Redis Engine – 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?
- Emergency: system is unusable
- Alert: action must be taken immediately
- Critical: critical conditions
- Error: error conditions
- Warning: warning conditions
- Notice: normal but significant condition
- Info: informational messages
- 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 parameters 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 sample code can detect environment in CakePHP:
$this->request->addDetector(
'post',
array('env' => 'REQUEST_METHOD', 'value' => 'POST')
);
How to detect pattern value in CakePHP?
Sample code 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;
Hope you will find this segment useful. If you have any questions that you want to share, please let us know. We find the answers and will publish after reviewed by experts.