About Cakephp Interview Preparation
CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. It uses commonly known design patterns like MVC and ORM within the convention over configuration paradigm.
For better preparation, read each question carefully, understand the concept, prepare one real example,
and connect your answer with your project or work experience.
Cakephp Questions List
Quick list of important Cakephp interview questions. Detailed answer previews are available below.
- When CakePHP was developed?
- What is cakephp?.
- What are are drawbacks of cakephp.
- What is MVC (model, view, and controller) in cakephp?
- What is the name of Cakephp database configuration file name and its location?
- What are component, helper and why are they used?
- What are commonly used components of cakephp?
- What is default function and default controller of cakephp which is called automatically?
- How cakephp URL looks in address bar
- Why cakephp have two vendor folder?
- List some database related functions in cakephp.
- List some of the features in Cakephp
- Server requirements for CakePHP.
- How to install CakePHP?
- What is the first file that gets loaded when you run a application using cakephp?can you change that file?
- What is the use of Security.salt and Security.cipherSeed in cakephp? How to change its default value?
- What is the naming convention in cakephp?
- What is Scaffolding in Cakephp?
- How to add Scaffolding in your application?
- What is a Behavior?
- What are commonly used helpers of cakephp?
- What is the difference between Component, Helper, Behavior?
- What is a Element?
- What is a layout?
- How to set layout in the controller?
- How to include helpers in controller ?
- How to include components in controller ?
- How to write, read and delete the Session in cakephp?
- What is the use of $this->set();
- What is the use of $this->set(compact());
Question 1: When CakePHP was developed?
Answer: Cake PHP started in 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)
View detailed answer →
Question 2: What is cakephp?.
Answer: 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
View detailed answer →
Question 3: What are are drawbacks of cakephp.
Answer: 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.
View detailed answer →
Question 4: What is MVC (model, view, and controller) in cakephp?
Answer: 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
View detailed answer →
Question 5: What is the name of Cakephp database configuration file name and its location?
Answer: Default file name is database.php.default. Its located in "/app/config/database.php.defaut"
View detailed answer →
Question 6: What are component, helper and why are they used?
Answer: 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).
View detailed answer →
Question 7: What are commonly used components of cakephp?
Answer: Following are some components which is used in cakephp. Security Sessions ACL(Access control lists) Auth(Authentication) Emails Cookies RequestHandling MVC architecture Built-in validations Caching scaffolding
View detailed answer →
Question 8: What is default function and default controller of cakephp which is called automatically?
Answer: Default controller is indexController.php and Default function isindex.
View detailed answer →
Question 9: How cakephp URL looks in address bar
Question 10: Why cakephp have two vendor folder?
Answer: There is two vendor folder, one folder in root and another is in "app" folder
View detailed answer →
Question 11: List some database related functions in cakephp.
Question 12: List some of the features in Cakephp
Answer: Following are some feature of Cakephp. *Full support of (MVC)Model, View, Controller Architecture.*Scaffolding.*Very nice Code generation via Bake.*Helpers for HTML, Forms, Pagination, AJAX, Javascript, XML, RSS and more.*Access Control Lists and Authentication (ACL & Auth).*Router for mapping urls and handling extensions.*Security, Session, and RequestHandler Components.*Utility classes for working with Files, Folders, Arrays and more.*can manage multiple site(apps) developement.*Internationalization and Localization with static translations in gettext style or dynamic translations of model data.*Full Console environment with support for...
View detailed answer →
Question 13: Server requirements for CakePHP.
Answer: 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)
View detailed answer →
Question 14: How to install CakePHP?
Answer: 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.
View detailed answer →
Question 15: What is the first file that gets loaded when you run a application using cakephp?can you change that file?
Answer: bootstrap.php yes it can be changed.Either through index.php , or through .htaccess
View detailed answer →
Question 16: What is the use of Security.salt and Security.cipherSeed in cakephp? How to change its default value?
Answer: -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.
View detailed answer →
Question 17: What is the naming convention in cakephp?
Answer: 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,
View detailed answer →
Question 18: What is Scaffolding in Cakephp?
Answer: Scaffolding is a technique that allows a developer to define and create a basic application that can create, retrieve, update and delete objects.
View detailed answer →
Question 19: How to add Scaffolding in your application?
Answer: To add scaffolding to your application,just add the $scaffold variable in the controller, <?php class PostsController extends AppController { var $scaffold; } ?>
View detailed answer →
Question 20: What is a Behavior?
Answer: Behaviors in CakePHP are associated with Models. Behaviors are used to change the way models behaves and enforcing model to act as something else.
View detailed answer →
Question 21: What are commonly used helpers of cakephp?
Answer: FormHelperHtmlHelperJsHelperCacheHelperNumberHelperPaginatorRSSSessionHelperTextHelperTimeHelper
View detailed answer →
Question 22: What is the difference between Component, Helper, Behavior?
Answer: Component is a Controller extension, Helpers are View extensions, Behavior is a Model Extension.
View detailed answer →
Question 23: What is a Element?
Answer: element in cakephp are smaller and reusable bits of view code. Elements are usually rendered inside views.
View detailed answer →
Question 24: What is a layout?
Answer: Layout in cakephp are used to display the views that contain presentational code. In simple views are rendered inside a layout
View detailed answer →
Question 25: How to set layout in the controller?
Answer: var $layout = ‘layout_name’; to overwrite for a specific action use below code in that action $this->layout =”layout_name”;
View detailed answer →
Question 26: How to include helpers in controller ?
Answer: public $helpers = array(‘Form’, ‘Html’, ‘Js’, ‘Time’); to in specific action use below code in that action $this->helper[] =”helper_name”;
View detailed answer →
Question 27: How to include components in controller ?
Answer: public $components = array(‘Emails’, ‘ImageUploader’, ‘Sms’);
View detailed answer →
Question 28: How to write, read and delete the Session in cakephp?
Answer: $this->Session->write(‘Bird.Color’, ‘Black’); $black = $this->Session->read(‘Bird.Color’); $this->Session->delete(‘Bird’);
View detailed answer →
Question 29: What is the use of $this->set();
Answer: 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.
View detailed answer →
Question 30: What is the use of $this->set(compact());
Answer: 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.
View detailed answer →
Question 31: What are the advantages of each?which would you use and why?
Answer: 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'));
View detailed answer →
Question 32: What is wrong with the below validation rule?
Answer: '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 chang...
View detailed answer →
Question 33: How to Get current URL in CakePHP?
Answer: 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/
View detailed answer →
Question 34: Why cakephp have two vendor folder?what is the difference between two vendors folder available in cakephp?
Answer: 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.
View detailed answer →
Question 35: What is the default extension of view files in cakephp?can we change it?if yes then how?
Answer: 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, i...
View detailed answer →
Question 36: How can you set custom page title for the static page?
Answer: 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");
View detailed answer →
Question 37: How to display the schema of the model?
Answer: 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());
View detailed answer →