Latest CakePHP Interview Questions
1 What is CakePHP?
CakePHP is a free, open-source, rapid development framework for PHP. It’s a foundational structure for programmers to create web applications. There is number of in built component like Ajax, RequestHandler, Session etc
2 What are are drawbacks of cakephp.
The learning curve, and it loads full application before it starts your task. Its not recommended for small projects because of its resource heavy structure.
3 What is MVC (model, view, and controller) in cakephp?
Model–view–controller (MVC) is an architectural pattern used in software engineering.
Model: Databases function exist in the model
View: Design parts written here
Controller: Business Login
4 What is the name of Cakephp database configuration file name and its location?
Default file name is database.php.default.
Its located in “/app/config/database.php.defaut”
5 What are component, helper and why are they used?
A component is an independent piece of code written for specific task that can be used(Eg Email, Ajax, RequestHandler and Session).
A helper is used for helping cakephp in rendering the data to be shown to user with views(Eg Form, HTML etc).
6 What are commonly used components of cakephp?
Security
Sessions
ACL(Access control lists)
Auth(Authentication)
Emails
Cookies
RequestHandling
MVC architecture
Built-in validations
Caching
scaffolding
7 What is default function and default controller of cakephp which is called automatically?
Default controller is indexController.php and Default function is index.
8 How cakephp URL looks in address bar?
http://example.com/controller/action/param1/param2/param3
9 Why cakephp have two vendor folder?
There is two vendor folder, one folder in root and another is in “app” folder
10 List some database related functions in cakephp.
find, findAll, findAllBy, findBy, findNeighbours and query.
11 List some of the features in Cakephp
Following are some feature of Cakephp.
MVC architecture
Built-in validations
Caching
scaffolding
12 Can you remember what is the directory structure when you download cakephp?
app/
o config/
o controllers/
o models/
o plugins/
o tmp/
o vendors/
o views/
o webroot/
* cake/
o config/
o docs/
o libs/
* vendors/
13 List some of the features in Cakephp.
1. Compatible with versions 4 and 5 of PHP
2. MVC architecture
3. Built-in validations
4. Caching
5. scaffolding
14 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.php, controller names are plural and CamelCased with *Controller* appended: ControllerNamesController, controller filenames are plural and underscored with *controller* appended: controller_names_controller.php,
15 How can we use ajax in cakephp?
By calling ajax helper and then using it in controller for rendering.
16 What is a component, helper and why are they used, is there other way we can do same thing, what is better.
A component is an independent piece of code written for specific task that can be used by calling in controllers (example : email component), helper is used for helping cakephp in rendering the data to be shown to user with views, these only adds to modularity in code otherwise same coding can be implemented in conrollers.
17 If you have to validate a registration module for a user, what all can be possible ways , which one is the best?
can be done on submission in controller, or using javascript/ajax while user is still filling the data. second option is better.
18 How can you include a javascript menu throughout the site. Give steps.
By adding the javascript files in webroot and call them in default views if needed everywhere or just in the related veiws.
19 What is a Component in cakephp?
Components are packages of logic that are shared between controllers. They are useful when a common logic or code is required between different controllers.
20 What are commonly used components of cakephp?
1. Security
2. Sessions
3. Access control lists
4. Emails
5. Cookies
6. Authentication
7. Request handling
21 When CakePHP was developed?
Cake php started at april 2005.When a Polish programmer Michal Tatarynowicz wrote a minimal version of a Rapid Application Framework in PHP, dubbing it Cake. Cake php version 1.0 released in May 2006. (source:http://en.wikipedia.org/wiki/CakePHP)
22 What is the current stable version of CakePHP?
2.5.4 (at the time of writing this post) released on 2014-09-02.
23 What is 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: sessions, mod_rewrite (not absolutely necessary but preferred)
PHP 4.3.2 or greater. Yes, CakePHP works great in either PHP 4 or 5.
A database engine (right now, there is support for MySQL 4+, PostgreSQL and a wrapper for ADODB).
24 How to install CakePHP?
There are below steps to follow:
step1: Go to cakephp.org 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.
25 Which is the first file that gets loaded when you run a application using cakephp? Can you change that file?
bootstrap.php is the file which is loaded first when application run. Yes, it can be changed either through index.php or .htaccess.
26 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 can change the default Security.salt value in /app/Config/core.php. And the Security.cipherseed is used for encrypt/decrypt strings. We can change the default Security.cipherSeed value by editing /app/Config/core.php.
27 What is Scaffolding in Cakephp? How to add Scaffolding in your application?
Scaffolding is a technique that allows a developer to define and create a basic application that can create, retrieve, update and delete objects. To add scaffolding to your application, just add the $scaffold variable in the controller.
1
Assuming you’ve created Post model class file (in /app/Model/post.php), you’re ready to go. Visit http://example.com/posts to see your new scaffold.
28 What is a Helper? What are commonly used helpers of cakephp?
Helpers in CakePHP are associated with Presentation layers of application. Helpers mainly contain presentational logic which is available to share between many views, elements, or layouts.
Below are the helpers which is used in cakephp:
FormHelper
HtmlHelper
JsHelper
CacheHelper
NumberHelper
Paginator
RSS
SessionHelper
TextHelper
TimeHelper
29 What is a Behavior?
Behaviors in CakePHP are associated with Models. Behaviors are used to change the way models behaves and enforcing model to act as something else.
30 What is the difference between Component, Helper, Behavior?
Component is a Controller extension, Helpers are View extensions, Behavior is a Model Extension.
31 What is a Element?
Element in cakephp are smaller and reusable bits of view code. Elements are usually rendered inside views.
32 What is a layout?
Layout in cakephp are used to display the views that contain presentational code. In simple views are rendered inside a layout.
33 How to set layout in the controller?
var $layout = ‘layout_name’; to overwrite for a specific action use below code in that action $this->layout =”layout_name”;
34 How to include helpers in controller?
public $helpers = array(‘Form’, ‘Html’, ‘Js’, ‘Time’); to in specific action use below code in that action $this->helper[] =”helper_name”;
35 How to include components in controller?
public $components = array(‘Emails’, ‘ImageUploader’, ‘Sms’);
36 How to write, read and delete the Session in cakephp?
$this->Session->write(‘MysessionVar’, ‘MysessionVal’);
$this->Session->read(‘MysessionVar’);
$this->Session->delete(‘MysessionVar’);
37 What is the use of $this->set();
The set() method is used for creating a variable in the view file. For Example, if we write, $this->set(‘posts’,$posts); in controller fie, then the variable $posts will be available to use in the view template file for that action.
38 Which methods are used to create and destroy model associations on the fly?
The bindModel() and unbindModel() Model methods are used to create and destroy model associations on the fly.
39 What is the use of requestAction method?
The method requestAction is used to call a controller’s action from any location and returns data from the action.
40 What is the default extension of view files in cakephp? Can we change it? If Yes then how?
The default extension of view files is ‘.ctp’. Yes we can change it by writing public $ext = ‘.yourext’; in AppController. If you want to change it for particular controller then add it into that controller only. You can also change it for the specific action of the controller by putting it in that action of controller.
public $ext = ‘.yourext’; in AppController
– you can change all the views extentions.
public $ext = ‘.yourext’; in specific controller like, PostsController
– you can change all the views extentions of PostsController.
public $ext = ‘.yourext’; in specific controller action like, index()
– you can change the view extention of index.ctp
Note: You cannot specify multiple extensions, however it seems like there is a fall back to .ctp if no .php file is found.