75 TOP Real Time CakePHP multiple choice questions and answers PDF

Read the most frequently asked 75 top CakePHP multiple choice questions and answers PDF for freshers and experienced

CakePHP Objective type Questions and Answers List

1. Which CakePHP entities can the Bake console create?
A. Controller
B. All of these
C. Model
D. View
Ans: B

2. How does one add scaffolding to an application?
A. class CategoriesController extends AppController { public $scaffold; }
B. None of these
C. class CategoriesController expands AppController { public $scaffoldx12 }
D. class CategoriesController extends AppController { public $scaffolding$ }
Ans: A

3. Which by is not a core find type provided by CakePHP?
A. first
B. all
C. active
D. threaded
E. neighbors
Ans: C

4. Is it possible to define custom data retrieval methods and if so, where would you define them?
A. Yes, create a component
B. Yes, as a controller function
C. Yes, in the routes
D. Yes, in the model
E. No, good luck
Ans: D

5. What CakePHP component is not part of the View layer?
A. Element
B. Helper
C. Layout
D. ViewClass
E. Behavior
Ans: E

6. In which controller callback would you preferably set “Auth->loginAction”?
A. loginFilter()
B. afterFilter()
C. _beforeScaffold($method)
D. beforeRender()
E. beforeFilter()
Ans: E

7. Which function is executed before every action in the controller.
A. beforeFilter
B. All of above
C. afterFilter
D. firstFilter
Ans: A

8. In cakePHP 2.x , the recursive property defines:
A. how deep CakePHP should go to fetch associated model data via find(), and read() methods
B. how many records to fetch by data via find(), and read() methods
C. how many time the find(), and read() methods are called
Ans: A

9. How will you include an element (header/footer etc.) within a layout?
A. element(‘element_name’); ?>
B. set(‘element_name’); ?>
C. include(‘element_name’); ?>
D.
Ans: A

10. Which of the following is an example of a model definition in CakePHP?
A. App::uses(‘AppModel’, ‘Model’); class Ingredient extends AppModel { public $name = ‘Ingredient’; }
B. CakePlugin::loadAll(); // Loads all plugins at once CakePlugin::load(‘ContactManager’); //Loads a single plugin
C. class IngredientsController extends AppController { public function index() {
D. None of these
Ans: A

11. What is the name of Cake’s database configuration file?
A. database.php.default
B. database.php
C. databaseconfig.php
D. default.database.php
E. config.php
Ans: B

12. True or False? Scaffolding in CakePHP also allows developers to define how objects are related to each other, and to create and break those links.
A. False
B. True
Ans: B

13. True or False? CakePHP will dynamically create a model object for you if it cannot find a corresponding file in /app/Model.
A. True
B. False
Ans: A

14. Which of the following function will be called before any action get executed ?
A. render
B. index
C. beforeFilter
D. beforeRender
E. afterFilter
Ans: C

15. Which file is processed first?
A. bootstrap.php
B. index.php
Ans: B

16. The association types in CakePHP are:
A. hasOne, hasMany, belongsTo, and hasAndBelongsToMany
B. oneToOne, oneToMany, manyToOne, manyToMany
C. hasAll, hasMany, belongsTo, manyToMany
D. hasAll, hasMany, belongsTo
Ans: A

17. What should be done before deploying a CakePHP application?
A. Disable debug messages in core.php
B. Disable exception stack traces
C. Set document root to app/webroot
D. All of them
E. Make sure data is sanitized and validated
Ans: D

18. CSRF protection is provided in CakePHP 2.x in
A. None of above
B. SecurityMethods
C. SecurityComponent
D. SecurityPlugin
Ans: C

19. Which data retrieval function will return one result only?
A. find(‘list’, $options)
B. find(‘first’, $options)
C. find(‘threaded’, $options)
D. find(‘one’, $options)
E. find(‘all’, $options)
Ans: B

20. What is the AppController class?
A. It is responsible for converting the POST parameters into a request object.
B. None of these.
C. It sets the initial configuration for plugins and caching.
D. It builds and manages paths to various components of the application.
E. It is the parent class to all of the application’s controllers.
Ans: E

21. By default, what controller action will be invoked if the action is not specified in the URL?
A. add
B. view
C. index
D. default
Ans: C

22. What is the default action for a controller?
A. index() function
B. None of these
C. _index() function
D. main() function
E. control() function
Ans: A

23. What is a .ctp file?
A. Common Timing Protocol
B. misnamed
C. Twig Template
D. CakePHP Template
E. PHP Container File
Ans: D

24. How is the AppController class defined?
A. $data = array( ‘color’ => ‘pink’, ‘type’ => ‘sugar’
B. class AppController extends Controller { }
C. public function beforeFilter() { parent::beforeFilter(); }
D. None of these
Ans: B

25. True or False? CakePHP favors convention over configuration.
A. True
B. False
Ans: A

26. The Bake console can be used to create:
A. none of above
B. models and views only
C. models only
D. models, views and controllers
E. models and controllers only
Ans: D

27. Which of email transports can be used in CakeEmail?
A. Only Mail and Smtp
B. Mail, Smtp and your own
C. Only Mail
D. Only Smtp
Ans: B

28. According to the CakePHP naming conventions, which of the following is a correct name for a controller file?
A. QuestionController
B. questionController
C. questionsController
D. QuestionsController
Ans: D

29. How does one create a virtual field?
A. public function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds);
B. public $virtualFields = array( ‘name’ => ‘CONCAT(User.first_name, ” “, User.last_name)’ );
C. None of these
D. class Category extends AppModel { public $actsAs = array(‘Tree’); }
Ans: B

30. What does MVC stand for?
A. Maximum-velocity-counter
B. Model-view-controller
C. Modular-view-controlling
D. Module-vector-core
Ans: B

31. True or False? CakePHP is based on the MVC design pattern.
A. False
B. True
Ans: B

32. Which is the default controller provided to serve static content?
A. StaticController
B. PagesController
C. HtmlController
D. ContentController
Ans: B

33. Which is not a core Component in CakePHP?
A. DebugKit
B. Security
C. RequestHandler
D. Paginator
Ans: A

34. echo ”

; print_r($array); echo

; what we write for these three lines in CakePhp.
A. print_preArray($array);
B. print_array();
C. debug_array($array);
D. print_pre_array($array);
E. debug($array);
Ans: E

35. You want to generate three instances of a model form within the context of a view. What syntax is most correct to use with FormHelper::input() ? $i represents an incremented variable.
A. $this->Form->input(“fieldname.$i.Modelname”);
B. $this->Form->input(“Modelname.$i.fieldname”);
C. $this->Form->input(“$i.Modelname.$i.fieldname”);
D. $this->Form->input(“$i.fieldname”);
Ans: B

36. True or False? Your own validation methods must have public visibility.
A. True
B. False
Ans: A

37. What kind of functionality does the Security Component provide?
A. Form tampering protection
B. CSRF protection
C. All of these
D. Restricting which HTTP methods the application accepts
E. Requiring that SSL be used
Ans: C

38. Which file may NOT be used to configure Cache settings?
A. bootstrap.php
B. core.php
C. routes.php
Ans: C

39. How does one create a transaction?
A. $dataSource->begin(); // Perform some tasks if (/*all’s well*/) { $dataSource->commit(); } else { $dataSource->rollback(); }
B. $this->Comment->delete($this->request->data(‘Comment.id’));
C. None of these
D. class User extends AppModel { public $validate = array( ‘login’ => ‘alphaNumeric’, ’email’ => ’email’, ‘born’ => ‘date’ ); }
Ans: A

40. What’s the name of the variable that holds a model validation rules?
A. $validate
B. $rules
C. $validationRules
D. $validation
Ans: A

41. Which of the following is an example of the definition of the find list function?
A. None of these
B. find(string $type = ‘list’, array $params = array())
C. find(‘first’, $params)
D. find(‘list’, $params)
Ans: D

42. What is the first file that gets loaded when you run a application using cakephp?
A. index.php
B. config.php
C. bootstrap.php
D. core.php
Ans: A

43. As related to the web server configuration, where is the index file properly located?
A. The webroot directory.
B. The top-level directory.
C. The system root directory.
D. The app directory.
Ans: A

44. How can you share logic between controllers?
A. Components
B. Helpers
C. Views
D. Behaviors
E. ControllerHelpers
Ans: A

45. What is the function of a model?
A. They are used to mediate input between Views and Controllers.
B. It is an object that represents application data, business rules and logic.
C. It is responsible for generating the specific output required for the request
Ans: B

46. To automatically get CSRF (Cross-site Request Forgery) and form tampering protection in CakePHP, what should be done?
A. Only use the Security Component
B. Use the FormHelper to create forms and add the Security Component to the controller
C. No need to do anything extra
D. Install Anti-Virus
E. Only use the FormHelper
Ans: B

47. True or False? CakePHP plugins are loaded automatically.
A. False
B. True
Ans: A

48. What does the ACL (Access Control Lists) Component provide?
A. Availability
B. Encryption
C. Authorization
D. Authentication
E. Integrity
Ans: C

49. CakePHP uses concept of _____
A. Configuration over Convention
B. Convention over configuration
Ans: B

50. What happens if CakePHP can’t find a file for a model object in the /app/Model folder?
A. Deletes the controller
B. Generates a SQL error
C. Generates an internal server error
D. Dynamically creates a model object for you
Ans: D

51. Which data retrieval function call is most suitable to build input select boxes?
A. find(‘first’)
B. field(‘list’)
C. find(‘all’)
D. find(‘select’)
E. find(‘list’)
Ans: E

52. Which model method requires values to be manually escaped?
A. Model::read()
B. Model::saveAssociated()
C. Model::saveField()
D. Model::query()
E. Model::find()
Ans: D

53. Which one is NOT a valid behavior callback?
A. beforeDelete()
B. beforeInitialize()
C. beforeSave()
D. afterFind()
E. beforeValidate()
Ans: B

54. Which database storage engine is not supported by the core installation?
A. MongoDB
B. PostgreSQL
C. Microsoft SQL Server
D. MySQL
E. SQLite
Ans: A

55. What is the proper way to delete a record?
A. None of these
B. deleteAll(mixed $conditions, $cascade = true, $callbacks = false)
C. delete(int $condition = null, boolean $cascade = true);
D. delete(int $id = null, boolean $cascade = true);
Ans: D

56. When using the function query() to retrieve data what should you do?
A. Instantiate a database connection
B. Limit number of results to 500
C. Pass conditions in an array
D. Place in a callback method
E. Clean up user-provided data from injection and cross-site scripting attacks
Ans: E

57. Which data retrieval function call is not valid? (Table: users; Columns: id, email, name, username)
A. findById()
B. findByUsername()
C. findByAllEmail()
D. query(“select * from users”)
E. findAllByName()
Ans: C

58. How can you load all plugins at once?
A. CakePlugin::load(‘all’)
B. CakePlugin::load(true)
C. App::loadAllPlugins()
D. Plugin::loadAll()
E. CakePlugin::loadAll()
Ans: E

59. Which data retrieval function call is the most suitable to build nested results with the parent_id field?
A. get(‘nested’)
B. find(‘threaded’)
C. find(‘nested’)
D. field(‘all’)
E. find(‘all’)
Ans: B

60. What is the default value of $recursive?
A. 1
B. null
C. 2
D. -1
E. 0
Ans: A

61. Which of the following is not a built in ConsoleOutput style?
A. question
B. warning
C. flash
D. comment
E. info
Ans: C

62. In the context of Views, what do helper classes do?
A. Form the meat of the application’s response
B. View files that contain presentational code that is found wrapping many interfaces in your application
C. None of these
D. Build forms, build AJAX functionality, or serve RSS feeds
Ans: D

63. What will the following example do (The order_items table has Order.order_id as a foreign key)? $this->Order->deleteAll(array(‘Order.complete’ => true), false);
A. Deletes all orders and order_items
B. Deletes only orders that are complete
C. Deletes all order_items that have completed orders
D. Deletes all orders that are incomplete
E. Deletes orders that are complete and the associated order_items
Ans: B

64. hich class handles request parameters and contains any data submitted with the request?
A. CakeResponse
B. CakeRequest
C. HttpSocketRequest
D. RequestHandler
E. Controller::$params
Ans: B

65. What class in CakePHP must be active in order for a user to see the error, “The request has been black-holed”?
A. RequestHandlerComponent
B. BaseAuthenticate
C. AuthComponent
D. SecurityComponent
E. UserModel
Ans: D

66. How would you express the following SQL condition in CakePHP (>=1.3.x)? “WHERE User.username NOT IN (‘jdoe’,’jsmith’,’ajones’)”
A. array(“NOT”=>array(“User.username”=>array(‘jdoe’,’jsmith’,’ajones’)))
B. None of these
C. array(“User.username”=>array(“NOT”=>array(‘jdoe’,’jsmith’,’ajones’)))
D. array(“User.username NOT IN “=>array(‘jdoe’,’jsmith’,’ajones’))
Ans: A

67. Which of the following is NOT a View Class in CakePHP?
A. XML
B. JSON
C. Media
D. XHTML
E. Themes
Ans: D

68. Which of the following is NOT a settable parameter used in Media views?
A. id
B. extension
C. name
D. download
E. category
Ans: E

69. Which route only passes integers to the controller action?
A. Router::connect(‘/blog/:id’, array(‘controller’ => ‘blog’, ‘action’ => ‘view’), array(‘pass’ => array(‘id’), ‘id’ => ‘[a-z][0-9]+’));
B. Router::connect(‘/blog/:id’, array(‘controller’ => ‘blog’, ‘action’ => ‘view’), array(‘id’ => ‘[0-9]+’));
C. Router::connect(‘/blog/:id’, array(‘controller’ => ‘blog’, ‘action’ => ‘view’), array(‘pass’ => array(‘id’), ‘id’ => ‘[0-9]+’));
D. Router::link(‘/blog/:id’, array(‘controller’ => ‘blog’, ‘action’ => ‘view’), array(‘pass’ => array(‘id’), ‘id’ => ‘[0-9]+’));
Ans: C

70. Which of the following is not a way to retrieve data from a model?
A. (in Model) $this->findAllByActive(‘true’);
B. (In Model) $this->find(‘all’, array(‘conditions’ => array(‘active’ => true)));
C. (In ModelController) $this->Model->find(‘all’, array(‘conditions’ => array(‘active’ => true)));
D. (In ModelController) $this->find(‘all’, array(‘conditions’ => array(‘active’ => true)));
Ans: D

71. When unit testing controller actions with ControllerTestCase, which of the following is NOT a built-in return type:
A. vars – Get the set view variables.
B. contents – Get the rendered view, including layout.
C. params – Get the values of all method parameters passed.
D. view – Get the rendered view, without a layout.
E. result – Get the return value of the controller action.
Ans: C

72. Which one below is not a Session configuration option?
A. Session.terminate
B. Session.cookie
C. Session.handler
D. Session.autoRegenerate
E. Session.ini
Ans: A

73. Which of the following is NOT a method that must be implemented for all CRUD methods?
A. calculate($model, $func, $params)
B. find(‘list’, $params)
C. listSources($data = null)
D. describe($model)
Ans: B

74. On which layer could you implement your own paginateCount() method?
A. Helper
B. Controller
C. Behavior
D. DataSource
Ans: c

75. Which TextHelper method allows you to transform links inside any text to valid HTML link tags?
A. processLinks()
B. automaticUrls()
C. autoLink()
D. addLinks()
Ans: C

76. Which of the following is not a built-in validation rule name?
A. ‘custom’
B. ‘datetime’
C. ‘between’
D. ‘alphanumeric’
E. ‘inList’
Ans: D

77. Which testing method allows you to test HTML generation easily?
A. assertHTML()
B. assertTags()
C. assertCode()
D. assertOutput()
Ans: B

This entry was posted in CakePHP MCQs and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *