Top 31 CakePHP Interview Questions for 2021
1) What is CakePHP?
CakePHP is an open-source PHP framework. It is used to develop dynamic web applications. It helps to developers to work in a structured manner.
2) When cakePHP was developed?
CakePHP was developed by Michal Tatarynowicz a Polish programmer, in April 2005.
3) What are the system requirements for CakePHP?
System requirements for CakePHP are:
- PHP 5.4.16 or greater
- mbstring extension library
- intl extension
- MySQL (5.1.10 or greater).
4) What is MVC in CakePHP?
In CakePHP, Model View Controller (MVC) is an application design pattern. It consists of three components.
Model: Database functions exist in the model or a representation of database table.
View: Design parts written here or client user interface
Controller: It controls the client request and respond back.
5) Where does the database configuration file reside in CakePHP?
CakePHP stores configure file here: /app/config/database.php.default
6) What are the features of CakePHP?
CakePHP provides various significant features that are listed below:
- MVC architecture
- Built-in validations
- Caching
- Scaffolding
- Auth & ACL
- CSRF protection via Security Component etc.
7) How can we install CakePHP?
We can install CakePHP on windows operating system using following steps:
step1: Go to cakephp.org website and download the latest version of CakePHP.
step2: Cakephp comes in a .zip file,so unzip it.
step3: Extract the files in the localhost in the desired folder (for example:cakephp).
step4: Open the browser and run the URL localhost/cakephp
step5: Just follow the instructions display on the page.
8) What is scaffolding in CakePHP?
In CakePHP, scaffolding is a practical way that allows developer to define and create a basic application like:
- Create
- Retrieve
- Update
- delete objects
9) How do callback functions work in CakePHP?
In CakePHP, callback functions work like this:
/** In controller**/
$userData = array();
$this->User->InsertRecord($userData );
/** In controller**/
/** In model **/
function InsertRecord($userData){
$this->save($userData);
}
function beforeSave(){
}
function AfterSave(){
}
10) What are associations and its type in CakePHP?
In CakePHP, associations are used to access the data from database. There are various types of associations that shown in the given table:
Relationship | Association Type | Example in single Line |
---|---|---|
one to one | hasOne | A user has one profile. |
one to Many | Has Many | A user can have multiple recipes. |
Many to one | Belongs To | Many recipes belong to a user. |
Many to Many | Has and belongs to many | Recipes have, and belong to, many ingredients. |
11) What are the components of CakePHP?
CakePHP is a set of following components that make it awesome and popular.
- Security
- Sessions
- Access control lists
- Emails
- Cookies
- Authentication
- Request handling
- Scaffolding
12) What is a helper?
In CakePHP, helpers are associated with presentation layers of application. Helpers mainly contain presentation logic.
13) What are the commonly used helpers of cakephp?
Following are the various helpers available in cakephp.
- FormHelper
- HtmlHelper
- JsHelper
- CacheHelper
- NumberHelper
- Paginator
- RSS
- SessionHelper
- TextHelper
- TimeHelper etc.
14) How can we set layout in the controller in CakePHP?
We can set the layout in controller using following code:
var $layout = "layout_name";
to overwrite for a specific action use below code in that action
$this->layout ="layout_name";
15) How to include components in CakePHP controller?
Controller includes following component :
public $components = array('Emails', 'ImageUploader', 'Sms');
16) What is the use of $this->set() in CakePHP?
In CakePHP, the $this->set() method is used for creating a variable in the view file.
17) What are class name for email configuration transport?
There are various class names for email configuration transport:
- Mail : It is used to send mail by using PHP mail function.
- Smtp : Send using SMTP
- Debug : Do not send the email, just return the result
18) How to create an email delivery profiles?
We can create an email delivery profile by using following command:
'Email' => [
'default' => [
'transport' => 'default',
'from' => 'you@localhost',
],
],
19) How to change the structure of URL in application, without modify the whole code?
The following code is used to change the structure of URL in an application.
url( string|array|null $url null , boolean $full false )
20) What are the types of event functions in Cake PHP?
There are various types of events functions in Cake PHP:
Helper::beforeRender(Event $event, $viewFile) Helper::beforeRenderFile(Event $event, $viewFile) Helper::afterRender(Event $event, $viewFile) Helper::afterLayout(Event $event, $layoutFile) etc.
21) What is authentication and its type in Cake PHP?
In Cake PHP, authentication is the process of identify the correct user.
The following authentication types are:
- FormAuthenticate
- BasicAuthenticate
- DigestAuthenticate
22) What are the various logging levels in CakePHP?
In CakePHP, there is several of logging level in CakePHP.
Logging level | Description |
---|---|
Emergency | System is unusable. |
Alert | Action must be taken immediately. |
Critical | Critical conditions |
Error | Error conditions |
Warning | Warning conditions |
Notice | Normal but significant condition |
23) What is the use of session in CakePHP?
In CakePHP, the session is used to manage unique users across requests and stores data.
24) What is the method to write Cookies in CakePHP?
In CakePHP, write() method is used to write Cookies.
25) How can we encrypt and decrypt data in CakePHP?
In CakePHP, we can encrypt and decrypt data by using security library methods.
Syntax:
static Cake\Utility\Security::hash($string, $type = NULL, $salt = false)
26) How can we create validator in the controller?
We can create validator in controller by using given command:
use Cake\Validation\Validator;
$validator = new Validator();
27) Does Cake PHP support internationalization?
Yes, Cake PHP supports internationalization.
28) What is the latest version of Cak PHP?
The stable version of Cake PHP is 3.5.0.
29) What is the folder structure of CakePHP?
The folder of CakePHP is given below:
30) How to display the schema of the model?
The following code is used to display the schema of the table.
pr($this->Post->schema());
31) How to get current URL in CakePHP?
The following code is used to get current URL in CakePHP.