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.



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.
  • Caching.

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?

function beforeFilter()

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.
    Example:ModelName
  • Model filenames are singular and underscored.
    Example: model_name.php
  • Controller names are plural and CamelCased with *Controller* appended.
    Example:ControllerNamesController
  • Controller filenames are plural and underscored with *controller* appended.
    Example:controller_names_controller.php

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:



  • CacheHelper
  • Paginator
  • SessionHelper
  • TimeHelper
  • TextHelper
  • RSS
  • JsHelper
  • HtmlHelper
  • NumberHelper

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:
1: XcacheEngine
2: MemcacheEngine
3: RedisEngine
4: FileCache
5: ApcCache
6: Wincache
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?

 



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();

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.

 

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:
1: Session.handler
2: Session.cookie
3: Session.cookiePath
4: Session.timeout
5:Session.defaults
6:Session.ini

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
1: Controllers
2: Views
3: Helpers
4: Cells
5: Components
In a basic session object, to interact with the session in your views you can also use the Cake\View\Helper\SessionHelper.

 

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:

 

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.

Advertisements