Top 50 Cakephp Interview Questions
Q1. How To Get Current Url In Cakephp?
To get contemporary url in cakephp use,
echo Router::url($this->right here, true);
This will deliver full URL with hostname.If you need to get relative direction rather than full URL,then use the following code:
echo $this->right here;
This will produce absolute URL with the exception of hostname i.E. /controller/abc/xyz/
Q2. What Is The Use Of Security.Salt And Security.Cipherseed In Cakephp? How To Change Its Default Value?
The Security.Salt is used for generating hashes.We are able to change the default Security.Salt fee in /app/Config/center.Hypertext Preprocessor.
The Security.Cipherseed is used for encrypt/decrypt strings.We can change the default Security.CipherSeed value by modifying /app/Config/middle.Personal home page.
Q3. How To Set Layout In The Controller?
Var $layout = ‘layout_name’;
to overwrite for a selected movement use under code in that action
$this->format =”layout_name”;
Q4. What Is The Use Of Requestaction Method?
The approach requestAction is used to name a controller’s motion from any area and returns information from the movement.
Q5. What Is The Difference Between Component, Helper, Behavior?
Component is a Controller extension, Helpers are View extensions, Behavior is a Model Extension.
Q6. What Is A Element?
Element in cakephp are smaller and reusable bits of view code. Elements are usually rendered inside views.
Q7. How To Add Scaffolding In Your Application?
To add scaffolding for your software,simply upload the $scaffold variable within the controller,
<?Php
class PostsController extends AppController
var $scaffold;
?>
Assuming you’ve created Post model elegance file (in /app/Model/post.Hypertext Preprocessor).
Q8. Which Methods Are Used To Create And Destroy Model Associations On The Fly?
The bindModel() and unbindModel() Model techniques are used to create and break model associations on the fly.
Q9. How To Display The Schema Of The Model?
If you need to display the schema of unique model then you simply want to feature the subsequent unmarried line of code.For instance we've got “Posts” Controller.
Pr($this->Post->schema());
Q10. List Some Of The Features In Cakephp?
Compatible with versions 4 and five of PHP
MVC structure
Built-in validations
Caching
Scaffolding
Access Control Lists and Authentication.
CSRF protection thru Security Component.
Q11. What Are The Advantages Of Each?Which Would You Use And Why?
An advantage with first case $this->set('posts', $posts); is that it permits two exceptional names for the view file and controller document. For example, you may write some thing like $this->set('postData', $posts);. Now the variable name within the view document would be $postData.
The gain with the second one method $this->set(compact()); is less difficult to jot down, and useful in particular when we are placing several variables to the view.No need to add separate line for every variable as we've got with $this->set();
For example,
$this->set(compact('posts','users','reports'));
Q12. How Can You Include A Javascript Menu Throughout The Site. Give Steps.
By adding the javascript files in webroot and phone them in default views if wished everywhere or simply in the associated veiws.
Q13. What Is The First File That Gets Loaded When You Run A Application Using Cakephp?Can You Change That File?
Bootstrap.Personal home page
sure it can be changed.Either thru index.Personal home page , or thru .Htaccess
Q14. How To Write, Read And Delete The Session In Cakephp?
$this->Session->write(‘Bird.Color’, ‘Black’);
$black = $this->Session->study(‘Bird.Color’);
$this->Session->delete(‘Bird’);
Q15. What Is The Folder Structure Of Cakephp?
Cakephp/
app/
Config/
Console/
Controller/
Lib/
Locale/
Model/
Plugin/
Test/
tmp/
Vendor/
View/
webroot/
.Htaccess
index.Hypertext Preprocessor
lib/
plugins/
carriers/
.Htaccess/
index.Hypertext Preprocessor/
README.Md/
Q16. What Are Commonly Used Helpers Of Cakephp?
FormHelper
HtmlHelper
JsHelper
CacheHelper
NumberHelper
Paginator
RSS
SessionHelper
TextHelper
TimeHelper
Q17. What Is The Use Of $this->set();
The set() approach is used for growing a variable in the view report.Say for example if we write,
$this->set('posts',$posts); in controller fie, then the variable $posts may be available to use inside the view template document for that motion.
Q18. What Is The Use Of $this->set(compact());?
Using $this->set(compact()) , we are able to skip a couple of parameters to get admission to into the view file.
For instance,
$this->set(compact('posts','customers','reports'));
Now most of these variables may be available in respective view file.
Q19. What Is The Default Extension Of View Files In Cakephp?Can We Change It?If Yes Then How?
Default extension of view documents is '.Ctp'.
Yes we will change it via writing public $ext = '.Yourext'; in AppController.If you want to trade it for particular controller then add it into that controller best.You also can trade it for the precise action of the controller by means of setting it in that movement of controller.
Public $ext = '.Yourext'; in AppController
- you could alternate all the perspectives extentions.
Public $ext = '.Yourext'; in unique controller like, PostsController
- you can exchange all the views extentions of PostsController.
Public $ext = '.Yourext'; in unique controller action like, index()
- you could change the view extention of index.Ctp
Note: You can't specify more than one extensions, but it seems like there may be a fall again to .Ctp if no .Personal home page report is found.
Q20. What Is Scaffolding In Cakephp?
Scaffolding is a method that allows a developer to define and create a primary software that can create, retrieve, update and delete objects.
Q21. Can You List Some Database Related Functions In Cakephp?
Discover, findAll , findAllBy , findBy , findNeighbours and query.
Q22. What Is Habtm?
Has and belongs to many is a sort of institutions that may be defined in models for retrieving associated information throughout unique entities.
Q23. What Is A Helper?
Helpers in CakePHP are associated with Presentation layers of utility.Helpers specially contain presentational common sense that is to be had to share between many views, factors, or layouts.
Q24. What Is Recursive In Cakephp?
To recognize this subject matter comply with this publish :
Recursive in cakephp
Q25. What Is The Current Stable Version Of Cakephp?
3.Zero (on date 2015-06-12).
Q26. Is It Possible To Have Multiple Validation Rules Per Field In Cakephp?
Yes its possible.
Q27. Using Cakephp, What All Are Drawbacks?
It loads complete software earlier than it starts offevolved your venture. It's not advocated for small projects due to its aid-heavy shape.
Q28. How To Install Cakephp?
Step1: Go to cakephp.Org and down load the cutting-edge version of cakephp.
Step2: Cakephp comes in a .Zip report,so unzip it.
Step3: Extract the files within the localhost inside the preferred folder (for instance:cakephp).
Step4: Open the browser and run the URL localhost/cakephp
step5: Just Follow the instructions show on the web page.
Q29. What Is The Name Of Cakephp Database Configuration File Name And Its Location?
Default report name is database.Personal home page.Default.
Its placed at "/app/config/database.Php.Default".To connect with database it should be renamed to database.Php
Q30. How Can We Use Ajax In Cakephp?
By calling ajax helper after which using it in controller for rendering.
Q31. What Is Default Function For A Controller?
Index() function
Q32. What Is Cakephp?
CakePHP is a loose, open-source, speedy improvement framework for PHP. It’s a foundational shape for programmers to create internet programs. CakePHP purpose is to enable developers to paintings in a based and rapid manner–with out loss of flexibility. CakePHP takes the monotony out of net development.
Q33. What Are Controllers?
A controller is used to manipulate the good judgment for a part of your utility. Most normally, controllers are used to control the common sense for a single version. Controllers can encompass any variety of strategies which might be usually known as moves. Actions are controller methods used to show views. An action is a unmarried technique of a controller.
Q34. Why Cakephp Have Two Vendor Folder?What Is The Difference Between Two Vendors Folder Available In Cakephp?
There will be vendor folders available in cakephp body paintings.
One in ” app ” folder and one in root folder
The vendor folder in the app folder is used to region the 1/3-celebration libraries which might be application particular.
The supplier folder in the root folder is used to area the 0.33-party libraries that are used for more than one programs.
Q35. How Can You Set Custom Page Title For The Static Page?
To set a custom page title, replica-paste following code everywhere on your static web page (.Ctp) report:
$this->set("title_for_layout", "My web page identify");
Q36. What Is A Layout?
Layout in cakephp are used to show the views that incorporate presentational code. In easy perspectives are rendered inner a format.
Q37. What Is Cakephp Request Cycle?
A regular CakePHP request cycle starts with a user asking for a page or aid on your application. At a excessive degree, every request is going thru the following steps −
The webserver rewrite policies direct the request to webroot/index.Php.
Your application’s autoloader and bootstrap documents are executed.
Any dispatch filters which can be configured can take care of the request, and optionally generate a reaction.
The dispatcher selects an appropriate controller & movement based on routing guidelines.
The controller’s action is known as and the controller interacts with the desired Models and Components.
The controller delegates reaction creation to the View to generate the output resulting from the model statistics.
The view uses Helpers and Cells to generate the response body and headers.
The response is despatched lower back to the customer.
Q38. How To Include Helpers In Controller ?
Public $helpers = array(‘Form’, ‘Html’, ‘Js’, ‘Time’);
to in precise action use underneath code in that action
$this->helper[] =”helper_name”;
Q39. How Can You Make Urls Search Engine Friendly While Using Cakephp?
It's an automatic mission this is finished by means of cakephp.
Q40. How To Include Components In Controller ?
Public $additives = array(‘Emails’, ‘ImageUploader’, ‘Sms’);
Q41. Which Function Is Executed Before Every Action In The Controller?
Characteristic beforeFilter()
Q42. What Is A Component In Cakephp?
Components are applications of common sense which are shared among controllers. They are beneficial whilst a commonplace common sense or code is needed between unique controllers.
Q43. Server Requirements For Cakephp?
Here are the requirements for setting up a server to run CakePHP:
An HTTP server (like Apache) with the following enabled: periods, mod_rewrite (now not actually necessary but preferred)
PHP four.3.2 or greater. Yes, CakePHP works tremendous in either PHP four or @
A database engine (proper now, there is support for MySQL four+, PostgreSQL and a wrapper for ADODB).
Q44. What Are Commonly Used Components Of Cakephp?
Security
Sessions
Access manage lists
Emails
Cookies
Authentication
Request dealing with
Scaffolding
Q45. What Is Email Configuration In Cakephp?
Email may be configured in record config/app.Hypertext Preprocessor. It isn't required to define electronic mail configuration in config/app.Hypertext Preprocessor. Email may be used with out it; just use the respective methods to set all configurations one at a time or load an array of configs. Configuration for Email defaults is created using config() and configTrport().
Q46. What Is Wrong With The Below Validation Rule?
'e mail' => array(
'rule' => array(
'rule' => 'notEmpty',
'message' => 'Please Enter Email address.'
),
'rule' => array(
'rule' => 'e-mail',
'message' => 'Entered Email address is invalid.'
)
)
The problem is the primary rule notEmpty will never be referred to as because email rule will overwrite it.While using more than one validation policies for the equal discipline you must keep the guideline key "precise". In this case if we need to use multiple rules then, we will simple alternate the rule of thumb key names like,
'e mail' => array(
'rule1' => array(
'rule' => 'notEmpty',
'message' => 'Please Enter Email address.'
),
'rule2' => array(
'rule' => 'e-mail',
'message' => 'Entered Email cope with is invalid.'
)
)
Q47. What Is A Behavior?
Behaviors in CakePHP are related to Models.Behaviors are used to trade the manner fashions behaves and enforcing version to behave as something else.
Q48. What Is Mvc In Cakephp?
Model view controller (MVC) is an architectural pattern used in software program engineering.
Model : Database capabilities exist inside the version
View : Design components written right here
Controller : Business Logic is going here
Q49. What Is The Naming Convention In Cakephp?
Table names are plural and lowercased,model names are singular and CamelCased: ModelName, model filenames are singular and underscored: model_name.Hypertext Preprocessor, controller names are plural and CamelCased with *Controller* appended: ControllerNamesController, controller filenames are plural and underscored with *controller* appended: controller_names_controller.Personal home page.
Q50. When Cakephp Was Developed?
CakePHP started out in April 2005.When a Polish programmer Michal Tatarynowicz wrote a minimal version of a Rapid Application Framework in PHP, dubbing it Cake.CakePHP version 1.Zero launched in May 2006.
