Q:Describe the features of cakephp?
- These are the features of cakephp:
MVC pattern :Using Model you can insert,update,delete the data from database.
View contains the design pattern.
Controller contains all the business logic,which can modify the logic before interact 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 this 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,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 present in the presentation layer,which is used to share between 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 act like a component,which is used to separate and reuse the logic that means you can reuse your logic and no need to have 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 request comes to controller.
beforeRender function is executed before the view is rendered,that means when request goes to view from 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 name of the table as an argument.
5:This new instance is used to create new entity.
6:Set necessary values with the instance of new entity.
7:Now we have to call the save() method with TableRegistry class’s instance which will insert new record in 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?
[SyntaxHL]var $layout = ‘layout_name’;[/SyntaxHL]
Q:In cakephp how To Set Layout In The Controller?
[SyntaxHL]public $helpers = array(‘Form’, ‘Js’,‘Html’,‘Time’);[/SyntaxHL]
Q:In cakephp how To Include Components In Controller ?
[SyntaxHL]public $components = array(‘Emails’, ‘Sms’, ‘ImageUploader’);[/SyntaxHL]
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 updation 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 to identify 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 basic session object,to interact with the session in your views you can also use the Cake\View\Helper\SessionHelper.
[SyntaxHL]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’);[/SyntaxHL]
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 an user request a page.
These are 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 controllers action is then called and the controller only combine with the required Models and Components.
6.The controller substitute the initiated response to the View for 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:
[SyntaxHL]$this->set(“title_for_layout”, “Page title”);[/SyntaxHL]
Q:Describe how to display the schema of the model in cakephp?
To display the schema of 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 have 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.