Here there are many questions and answers about How CakePHP
Framework works? and basic questions related to CakePHP framework
functionality.
Q-1What
is CakePHP ?
Ans.
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
Q-2 What are are
drawbacks of cakephp.
Ans.
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.
Q-3 What is MVC (model,
view, and controller) in cakephp?
Ans.
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
Q-4 What is the name of
Cakephp database configuration file name and its location?
Ans.
Default file name is database.php.default.
Its
located in “/app/config/database.php.defaut”
Q-5 What are component,
helper and why are they used?
Ans.
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).
Q-6 What are commonly
used components of cakephp?
Ans.
Security
Sessions
ACL(Access
control lists)
Auth(Authentication)
Emails
Cookies
RequestHandling
MVC
architecture
Built-in
validations
Caching
scaffolding
Q-7 What is default
function and default controller of cakephp which is called automatically?
Ans.
Default controller is indexController.php and Default function is index.
Q-8 How cakephp URL
looks in address bar?
Ans.
http://example.com/controller/action/param1/param2/param3
Q-9 Why cakephp have
two vendor folder?
Ans.
There is two vendor folder, one folder in root and another is in “app” folder
Q-10 List some database
related functions in cakephp.
Ans.
find, findAll , findAllBy , findBy , findNeighbours and query.
Q-11 List some of the
features in Cakephp
Ans.
Following are some feature of Cakephp.
MVC
architecture
Built-in
validations
Caching
scaffolding
Q-12 can you remember
what is the directory structure when you download cakephp?
Ans.
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/
Q-13 List some of the
features in Cake php.
Ans.
1.
Compatible with versions 4 and 5 of PHP
2.
MVC architecture
3.
Built-in validations
4.
Caching
5.
scaffolding
Q-14 What is the naming
convention in cakephp?
Ans.
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,
Q-15 How can we use
ajax in cakephp?
Ans.
By calling ajax helper and then using it in controller for rendering.
Q-16 What is a
component,helper and why are they used, is there other way we can do same
thing, what is better.
Ans.
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.
Q-17 If you have to
validate a registration module for a user, what all can be possible ways ,
which one is the best?
Ans.
can be done on submission in controller, or using javascript/ajax while user is
still filling the data. second option is better.
Q-18 How can you
include a javascript menu throughout the site. Give steps.
Ans.
By adding the javascript files in webroot and call them in default views if
needed everywhere or just in the related veiws.
Q-19 What is a
Component in cakephp?
Ans.
Components are packages of logic that are shared between controllers. They are
useful when a common logic or code is required between different controllers.
Q-20 What are commonly
used components of cakephp?
Ans.
1.
Security
2.
Sessions
3.
Access control lists
4.
Emails
5.
Cookies
6.
Authentication
7.
Request handling
(21) 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. CakePHP goal
is to enable developers to work in a structured and rapid manner–without loss
of flexibility. CakePHP takes the monotony out of web development.
(22) 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)
(23) What is the
current stable version of CakePHP?
2.5.4
(at the time of writing this post) released on 2014-09-02.
(24) What is MVC in
CakePHP?
Model
view controller (MVC) is an architectural pattern used in software engineering.
Model:
Database functions exist in the model
View:
Design parts written here
Controller:
Business Logic goes here
To
understand in detail :
http://www.php-dev-zone.com/2013/07/mvc-architecture-of-cakephp.html
(25) 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).
(26) How to install
CakePHP?
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.
(27) What is the folder
structure of CakePHP?
cakephp/
app/
Config/
Console/
Controller/
Lib/
Locale/
Model/
Plugin/
Test/
tmp/
Vendor/
View/
webroot/
.htaccess
index.php
lib/
plugins/
vendors/
.htaccess/
index.php/
README.md/
(28) What is the name
of Cakephp database configuration file name and its location?
Default
file name is database.php.default.
Its
located at "/app/config/database.php.default".To connect with
database it should be renamed to database.php
(29) What is the first
file that gets loaded when you run a application using cakephp?can you change
that file?
bootstrap.php
yes
it can be changed.Either through index.php , or through .htaccess
(30) 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.
-
The Security.cipherseed is used for encrypt/decrypt strings.We can change the
default Security.cipherSeed value by editing /app/Config/core.php.
(31) What are
controllers?
A
controller is used to manage the logic for a part of your application. Most
commonly, controllers are used to manage the logic for a single model.
Controllers can include any number of methods which are usually referred to as
actions. Actions are controller methods used to display views. An action is a
single method of a controller.
(32) What is default
function for a controller?
index()
function
(33) Which function is
executed before every action in the controller?
function
beforeFilter()
(34) 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
6.
Access Control Lists and Authentication.
7.CSRF
protection via Security Component.
(35) Using cakephp,
what all are drawbacks.
it
loads full application before it starts your task. Its not recommended for
small projects because of its resource heavy structure.
(36) 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,
(37) What is
Scaffolding in Cakephp?
Scaffolding
is a technique that allows a developer to define and create a basic application
that can create, retrieve, update and delete objects.
(38) How to add
Scaffolding in your application?
To
add scaffolding to your application,just add the $scaffold variable in the
controller,
<?php
class
PostsController extends AppController {
var $scaffold;
}
?>
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.
(39) 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.
(40) What are commonly
used components of cakephp?
1.
Security
2.
Sessions
3.
Access control lists
4.
Emails
5.
Cookies
6.
Authentication
7.
Request handling
8.
Scaffolding
(41) What is a Helper?
Helpers
in CakePHP are associated with Presentation layers of application.
Helpers
mainly contain presentational logic which is availabel to share between many
views, elements, or layouts
(42) What are commonly
used helpers of cakephp?
FormHelper
HtmlHelper
JsHelper
CacheHelper
NumberHelper
Paginator
RSS
SessionHelper
TextHelper
TimeHelper
(43) 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.
(44) What is the
difference between Component, Helper, Behavior?
Component
is a Controller extension, Helpers are View extensions, Behavior is a Model
Extension.
(45) What is a Element?
Element
in cakephp are smaller and reusable bits of view code. Elements are usually
rendered inside views.
(46) 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
(47) 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”;
(48) 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”;
(49) How to include
components in controller ?
public
$components = array(‘Emails’, ‘ImageUploader’, ‘Sms’);
(50) How to write, read
and delete the Session in cakephp?
$this->Session->write(‘Bird.Color’,
‘Black’);
$black
= $this->Session->read(‘Bird.Color’);
$this->Session->delete(‘Bird’);
(51) What is the use of
$this->set();
The
set() method is used for creating a variable in the view file.Say 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.
(52) What is the use of
$this->set(compact());
Using
$this->set(compact()) , we can pass multiple parameters to access into the
view file.
For
example,
$this->set(compact('posts','users','reports'));
Now
all these variables will be available in respective view file.
(53) What are the
advantages of each?which would you use and why?
An
advantage with first case $this->set('posts', $posts); is that it allows two
different names for the view file and controller file. For example, you could
write something like $this->set('postData', $posts);. Now the variable name
in the view file would be $postData.
The
advantage with the second approach $this->set(compact()); is easier to
write, and useful especially when we are setting several variables to the
view.No need to add separate line for each variable as we have with
$this->set();
For
example,
$this->set(compact('posts','users','reports'));
(54) Is it possible to
have Multiple validation Rules per Field in cakephp?
Yes
its possible.
(55) What is wrong with
the below validation rule?
'email'
=> array(
'rule' => array(
'rule' => 'notEmpty',
'message' => 'Please Enter Email
address.'
),
'rule' => array(
'rule' => 'email',
'message' => 'Entered Email address
is invalid.'
)
)
The
problem is the first rule notEmpty will never be called because email rule will
overwrite it.While using multiple validation rules for the same field you must
keep the rule key "unique". In this case if we want to use multiple
rules then, we can simple change the rule key names like,
'email'
=> array(
'rule1' => array(
'rule' => 'notEmpty',
'message' => 'Please Enter Email
address.'
),
'rule2' => array(
'rule' => 'email',
'message' => 'Entered Email address
is invalid.'
)
)
(56) What is the
defference between required and notEmpty in cakephp?
To
understand this question read this post:
http://www.php-dev-zone.com/2014/08/difference-between-required-and.html
(57) How to Get current
URL in CakePHP?
To
get current url in cakephp use,
echo
Router::url($this->here, true);
This
will give full URL with hostname.If you want to get relative path instead of
full URL,then use the following code:
echo
$this->here;
This
will produce absolute URL excluding hostname i.e. /controller/abc/xyz/
(58) How can you make
urls search engine friendly while using cakephp?
It's
an automatic task that is done by cakephp.
(59) Can you list some
database related functions in cakephp?
find,
findAll , findAllBy , findBy , findNeighbours and query.
(60) 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.
(61) 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.
(62) What is recursive
in cakephp?
To
understand this topic follow this post :
Recursive
in cakephp
(63) How can we use
ajax in cakephp?
By
calling ajax helper and then using it in controller for rendering.
(64) What is habtm?
Has
and belongs to many is a kind of associations that can be defined in models for
retrieving associated data across different entities.
(65) How cakephp URL looks
in address bar?
http://example.com/controller/action/param1/param2/param3
(66) 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.
(67) Why cakephp have
two vendor folder?what is the difference between two vendors folder available
in cakephp?
There
will be two vendor folders available in cakephp frame work.
one
in ” app ” folder and one in root folder
The
vendor folder in the app folder is used to place the third-party libraries
which are application specific.
The
vendor folder in the root folder is used to place the third-party libraries
which are used for multiple applications.
(68) What is the default
extension of view files in cakephp?can we change it?if yes then how?
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.
(69) How can you set
custom page title for the static page?
To
set a custom page title, copy-paste following code anywhere in your static page
(.ctp) file:
$this->set("title_for_layout",
"My page title");
(70) How to display the
schema of the model?
If
you want to disply the schema of particular model then you just need to add the
following single line of code.For example we have “Posts” Controller.
pr($this->Post->schema());
It’s really a good post; actually I just begin to learn to get my career enhancement. Thanks for sharing the useful post I would to see your upcoming blogs here.
ReplyDeleteRegards,
PHP Training in Chennai|PHP Course in Chennai|PHP Training
Thanks for questions .You can find Latest CakePHP Questions from CakePHP Interview Questions.
ReplyDeleteThanks
Nice such an Informative blog. Very useful questions and exact answers for the same. Keep the good work up :)
ReplyDeleteThanks for sharing such a nice information with us. Very useful lines and to the point.
CakePHP Interview Questions Answers
CakePHP Advanced Interview Questions Answers
CakePHP Most Common Interview Questions Answers
Drupal Interview Questions Answers
MySQL Interview Questions Answers
MySQL Interview Questions Answers
Wordpress Advance Interview Questions Answers
OOPS Interview Questions Answers
PHP-MySQL Interview Questions Answers
I have read a few of the articles on your website now, and I really like your style of blogging. I added it to my favourites blog site list and will be checking back soon.
ReplyDeletepython training in Bangalore
python training in pune
python online training
python training in chennai
All the points you described so beautiful. Every time i read your i blog and i am so surprised that how you can write so well.
ReplyDeleteBlueprism training in tambaram
Blueprism training in annanagar
Blueprism training in velachery
Fantastic work! This is the type of information that should follow collective approximately the web. Embarrassment captivating position Google for not positioning this transmit higher! Enlarge taking place greater than and visit my web situate
ReplyDeleteData Science course in rajaji nagar | Data Science with Python course in chenni
Data Science course in electronic city | Data Science course in USA
Data science course in pune | Data science course in kalyan nagar
This is my 1st visit to your web... But I'm so impressed with your content. Good Job!
ReplyDeleteangularjs Training in btm
angularjs Training in electronic-city
angularjs online Training
angularjs Training in marathahalli
angularjs interview questions and answers
It was really a nice post and i was really impressed by reading thisRuby on Rails Online Training
ReplyDeleteThanks for sharing the valuable information with us.These are really great and useful in all aspects,appreciated!
ReplyDeleteCakePHP Most Comon Interview Questions
CakePHP Advance Interview Questions
CakePHP Interview Questions
I love what you’ve got to say. But maybe you could a little more in the way of content so people could connect with it better.
ReplyDeleteiosh course in chennai