Cakephp Interview Questions for Experienced
This post about the Cakephp interview questions for experienced. Here you can get 100 + tough CakePHP questions for an experienced candidate. It is another famous framework in PHP.
Table of Contents
- Q: Describe the features of CakePHP?
- Q:In cakephp,what is default function for a controller?
- Q: In the controller, which function is executed before every action?
- Q: What are the drawbacks of CakePHP?
- Q: Define naming convention in CakePHP?
- Q:Define Scaffolding in Cakephp?
- Q: Define Helper in CakePHP and what are those?
- Q: Define Hooks in cakephp?
- Q:Define Behavior in cakephp?
- Q: Explain the difference between beforeRender and beforeFilter function ?
- Q: Explain the Difference Between Component, Helper, Behavior?
- Q: What are the types of cache CakePHP support?
- Q: How CakePHP internally work with database?
- Q: Define Element in CakePHP?
- Q: Define Layout in CakePHP?
- Q: In the controller how to set Layout?
- Q: In cakephp how To Set Layout In The Controller?
- Q: In cakephp how To Include Components In Controller?
- Q: In cakephp how to read, write and delete the session?
- Q:What Is The Use Of $this->set();
- Q: In CakePHP how to update multiple data?
- Q: Define Sessions in CakePHP?
- Q: Define Session Configuration and what are the options available?
- Q: In CakePHP,how to access the session object?
- Q:In cakephp,define Email Configuration?
- Q: Describe CakePHP request cycle?
- Q: In a static page, how can you set custom page title?
- Q: Describe how to display the schema of the model in CakePHP?
- Q: Find the difference between two Vendors Folder available in Cakephp and why Cakephp has two Vendor Folder??
Q: Describe the features of CakePHP?
- These are the features of CakePHP:
MVC pattern: Using Model you can insert, update, delete the data from the database.
View contains the design pattern.
Controller contains all the business logic, which can modify the logic before interacting with the model.
With MVC pattern, it is very easy to separate the logic from presentation, which is useful for large applications and sites.
- Built in validation->In these features, you could attach multiple advanced validation rules to single field.
- CRUD scaffolding->It will save lot of time.
CRUD comes from Create, Read, Update, Delete – In most of web applications these are the main activities.
It is more helpful because with one single line of code you can see preliminary view of your application.
- Authentication and Access Control lists.
- CSRF protection via Security Component.
- Compatible with versions 4 and 5 of PHP.
Q:In cakephp,what is default function for a controller?
index() function is the default function.
Q: In the controller, which function is executed before every action?
Q: What are the drawbacks of CakePHP?
These are the drawbacks of CakePHP:
1: It is not suggested for small projects because of its resource-heavy structure.
Q: Define naming convention in CakePHP?
In CakePHP, the naming convention is:
- All the tables name are plural and lowercased.
- Model names are singular and CamelCased.
- Model filenames are singular and underscored.
- Controller names are plural and CamelCased with *Controller* appended.
- Controller filenames are plural and underscored with *controller* appended.
Q:Define Scaffolding in Cakephp?
It is a procedure which allows a developer to specify and create a basic application that can create,update,delete and retrieve objects.
Q: Define Helper in CakePHP and what are those?
In CakePHP, helpers contain presentational logic that presents in the presentation layer, which is used to share many views, elements, or layouts.
These are the helper used in CakePHP:
Q: Define Hooks in cakephp?
Hooks are the methods which can be used to call before and after doing any task in model.
e.g beforeSave(), afterSave(), beforeFind(), afterFind() etc.
Q:Define Behavior in cakephp?
In cakephp, Behavior is acted like a component, which is used to separate and reuse the logic that means you can reuse your logic and no need to have the same logic in different models.
Example: File uploading logic is handled by FileUpload behavior that can integrate with any number of model classes.
Q: Explain the difference between beforeRender and beforeFilter function ?
In cakephp,beforeFilter function is executed before every action in the controller, that means when the request comes to controller.
beforeRender function is executed before the view is rendered, that means when the request goes to view from the controller.
Q: Explain the Difference Between Component, Helper, Behavior?
These are the main difference:
1: Component is a Controller extension.
2: Helpers are View extensions.
3: Behavior is a Model Extension.
Q: What are the types of cache CakePHP support?
These are the list of cache:
The default cache engine is FileEngine.
Q: How CakePHP internally work with database?
1: First we have to create a table in the database.
2: Insert a record into the table, after that we need to hold the table using TableRegistry class.
3: Using get(), we can fetch the instance out of registry.
4: Then get() will take the name of the table as an argument.
5: This new instance is used to create a new entity.
6: Set necessary values with the instance of a new entity.
7: Now we have to call the save() method with TableRegistry class’s instance which will insert a new record in the database.
Q: Define Element in CakePHP?
In CakePHP,elements are smaller and reusable bits of view code. Elements are usually effected inside views.
Q: Define Layout in CakePHP?
In cakephp layouts are used to display the views which contain presentational code. Views are rendered inside a layout.
Q: In the controller how to set Layout?
var $layout = ‘layout_name’;
Q: In cakephp how To Set Layout In The Controller?
public $helpers = array(‘Form’, ‘Js’,‘Html’,‘Time’);
Q: In cakephp how To Include Components In Controller?
public $components = array(‘Emails’, ‘Sms’, ‘ImageUploader’);
Q: In cakephp how to read, write and delete the session?
$red = $this->Session->read(‘Color’);
Q:What Is The Use Of $this->set();
In the view file,set() method is used for creating a variable.
Example:In the controller file,we write $this->set(‘posts’,$posts);
then creating a $posts variable in the view file.
Q: In CakePHP how to update multiple data?
Cakephp allows the single row updating method, which can run 3 times form to update all row.
Update orderdetails SET data = "'.$json1.'" WHERE order_id = 1;
Update orderdetails SET data = "'.$json2.'" WHERE order_id = 2;
Update orderdetails SET data = "'.$json3.'" WHERE order_id = 3;
But I want to save this by just only one line code that can run above query.
$update = array(
array('data' => $json1,'order_id' => 1),
array('data' => $json2,'order_id' => 2),
array('data' => $json3,'order_id' => 3),
Q: Define Sessions in CakePHP?
In CakePHP, Sessions allows identifying unique users across requests. Sessions store continual data for specific users.
Q: Define Session Configuration and what are the options available?
In CakePHP,generally, Session Configuration is defined in /config/app.php.
These are the lists:
Q: In CakePHP,how to access the session object?
In CakePHP,You can access the session data at any place that you have access to a request object. That means the session is accessible at below places
In a basic session object, to interact with the session in your views you can also use the Cake\View\Helper\SessionHelper.
Example of session usage:
// Prior to 3.6.0 use session() instead.
$name = $this->getRequest()->getSession()->read('User.name');
// If you are accessing the session multiple times,
// you will probably want a local variable.
$session = $this->getRequest()->getSession();
$name = $session->read('User.name');
Q:In cakephp,define Email Configuration?
Ans: Email can be configured in file config/app.php. It is not required to define email configuration in config/app.php.
Email can be used without it; just use the respective methods to set all configurations separately or load an array of configs.
Configuration for Email defaults is created using config() and configTransport().
Q: Describe CakePHP request cycle?
In CakePHP,a request cycle starts when a user requests a page.
These are the steps:
1: Based on the webserver rewrite rules, the request is redirected to webroot/index.php file.
2: The bootstrap and autoloader files of the application gets executed.
3: Dispatch filters which are composed can handle the request, and then arise a response.
4: Dispatcher then selects the proper controller and action confer to the routing rules defined.
5: The controller’s action is then called and the controller only combines with the required Models and Components.
6. The controller substitutes the initiated response to the View to make the output resulting from the model data.
7. The view uses Helpers to make the response of the client request.
8. The created response is then sent back to the client.
Q: In a static page, how can you set custom page title?
Ans: Copy-paste the bellow code anywhere in the static page (.ctp) file, to set a custom page title:
$this->set("title_for_layout", "Page title");
Q: Describe how to display the schema of the model in CakePHP?
To display the schema of a particular model then you just need to add the single line of code, which is given below.
Example: Suppose we have “Posts” Controller, following is the code:
Q: Find the difference between two Vendors Folder available in Cakephp and why Cakephp has two Vendor Folder??
In CakePHP,there are two vendor folders available.
1: app folder->It is used to place the third-party libraries which are application-specific.
2: root folder->It is used to place the third-party libraries which are used for multiple applications.