Elance CakePHP Test Answers 2015





Which CakePHP entities can the Bake console create?
Controller
All of these
Model
View


How does one add scaffolding to an application?
class CategoriesController extends AppController { public $scaffold; }
None of these
class CategoriesController expands AppController { public $scaffoldx12 }
class CategoriesController extends AppController { public $scaffolding$ }


Which by is not a core find type provided by CakePHP?
first
all
active
threaded
neighbors


Is it possible to define custom data retrieval methods and if so, where would you define them?
Yes, create a component
Yes, as a controller function
Yes, in the routes
Yes, in the model
No, good luck


What CakePHP component is not part of the View layer?
Element
Helper
Layout
ViewClass
Behavior


In which controller callback would you preferably set "Auth->loginAction"?
loginFilter()
afterFilter()
_beforeScaffold($method)
beforeRender()
beforeFilter()


Which function is executed before every action in the controller.
beforeFilter
All of above
afterFilter
firstFilter


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


How will you include an element (header/footer etc.) within a layout?
<?php echo $this->element('element_name'); ?>
<?php echo $this->set('element_name'); ?>
<?php echo $this->include('element_name'); ?>
<?php include('element_name'); ?>


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


What is the name of Cake's database configuration file?
database.php.default
database.php
databaseconfig.php
default.database.php
config.php


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.
False
True


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


Which of the following function will be called before any action get executed ?
render
index
beforeFilter
beforeRender
afterFilter


Which file is processed first?
bootstrap.php
index.php


The association types in CakePHP are:
hasOne, hasMany, belongsTo, and hasAndBelongsToMany
oneToOne, oneToMany, manyToOne, manyToMany
hasAll, hasMany, belongsTo, manyToMany
hasAll, hasMany, belongsTo


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


CSRF protection is provided in CakePHP 2.x in
None of above
SecurityMethods
SecurityComponent
SecurityPlugin


Which data retrieval function will return one result only?
find('list', $options)
find('first', $options)
find('threaded', $options)
find('one', $options)
find('all', $options)


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


By default, what controller action will be invoked if the action is not specified in the URL?
add
view
index
default


What is the default action for a controller?
index() function
None of these
_index() function
main() function
control() function


What is a .ctp file?
Common Timing Protocol
misnamed
Twig Template
CakePHP Template
PHP Container File


How is the AppController class defined?
$data = array( 'color' => 'pink', 'type' => 'sugar'
class AppController extends Controller { }
public function beforeFilter() { parent::beforeFilter(); }
None of these


True or False? CakePHP favors convention over configuration.
True
False


The Bake console can be used to create:
none of above
models and views only
models only
models, views and controllers
models and controllers only


Which of email transports can be used in CakeEmail?
Only Mail and Smtp
Mail, Smtp and your own
Only Mail
Only Smtp


According to the CakePHP naming conventions, which of the following is a correct name for a controller file?
QuestionController
questionController
questionsController
QuestionsController


How does one create a virtual field?
public function __construct($id = false, $table = null, $ds = null) { parent::__construct($id, $table, $ds);
public $virtualFields = array( 'name' => 'CONCAT(User.first_name, " ", User.last_name)' );
None of these
class Category extends AppModel { public $actsAs = array('Tree'); }


What does MVC stand for?
Maximum-velocity-counter
Model-view-controller
Modular-view-controlling
Module-vector-core


True or False? CakePHP is based on the MVC design pattern.
False
True


Which is the default controller provided to serve static content?
StaticController
PagesController
HtmlController
ContentController


Which is not a core Component in CakePHP?
DebugKit
Security
RequestHandler
Paginator


echo "<pre>; print_r($array); echo </pre>; what we write for these three lines in CakePhp.
print_preArray($array);
print_array();
debug_array($array);
print_pre_array($array);
debug($array);


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.
$this->Form->input("fieldname.$i.Modelname");
$this->Form->input("Modelname.$i.fieldname");
$this->Form->input("$i.Modelname.$i.fieldname");
$this->Form->input("$i.fieldname");


True or False? Your own validation methods must have public visibility.
True
False


What kind of functionality does the Security Component provide?
Form tampering protection
CSRF protection
All of these
Restricting which HTTP methods the application accepts
Requiring that SSL be used


Which file may NOT be used to configure Cache settings?
bootstrap.php
core.php
routes.php


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


What's the name of the variable that holds a model validation rules?
$validate
$rules
$validationRules
$validation


Which of the following is an example of the definition of the find list function?
None of these
find(string $type = 'list', array $params = array())
find('first', $params)
find('list', $params)


What is the first file that gets loaded when you run a application using cakephp?
index.php
config.php
bootstrap.php
core.php


As related to the web server configuration, where is the index file properly located?
The webroot directory.
The top-level directory.
The system root directory.
The app directory.


How can you share logic between controllers?
Components
Helpers
Views
Behaviors
ControllerHelpers


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


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


True or False? CakePHP plugins are loaded automatically.
False
True


What does the ACL (Access Control Lists) Component provide?
Availability
Encryption
Authorization
Authentication
Integrity


CakePHP uses concept of _____
Configuration over Convention
Convention over configuration


What happens if CakePHP can't find a file for a model object in the /app/Model folder?
Deletes the controller
Generates a SQL error
Generates an internal server error
Dynamically creates a model object for you


Which data retrieval function call is most suitable to build input select boxes?
find('first')
field('list')
find('all')
find('select')
find('list')


Which model method requires values to be manually escaped?
Model::read()
Model::saveAssociated()
Model::saveField()
Model::query()
Model::find()


Which one is NOT a valid behavior callback?
beforeDelete()
beforeInitialize()
beforeSave()
afterFind()
beforeValidate()


Which database storage engine is not supported by the core installation?
MongoDB
PostgreSQL
Microsoft SQL Server
MySQL
SQLite


What is the proper way to delete a record?
None of these
deleteAll(mixed $conditions, $cascade = true, $callbacks = false)
delete(int $condition = null, boolean $cascade = true);
delete(int $id = null, boolean $cascade = true);


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


Which data retrieval function call is not valid? (Table: users; Columns: id, email, name, username)
findById()
findByUsername()
findByAllEmail()
query("select * from users")
findAllByName()


How can you load all plugins at once?
CakePlugin::load('all')
CakePlugin::load(true)
App::loadAllPlugins()
Plugin::loadAll()
CakePlugin::loadAll()


Which data retrieval function call is the most suitable to build nested results with the parent_id field?
get('nested')
find('threaded')
find('nested')
field('all')
find('all')


What is the default value of $recursive?
1
null
2
-1
0


Which of the following is not a built in ConsoleOutput style?
question
warning
flash
comment
info


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


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);
Deletes all orders and order_items
Deletes only orders that are complete
Deletes all order_items that have completed orders
Deletes all orders that are incomplete
Deletes orders that are complete and the associated order_items


Which class handles request parameters and contains any data submitted with the request?
CakeResponse
CakeRequest
HttpSocketRequest
RequestHandler
Controller::$params


What class in CakePHP must be active in order for a user to see the error, "The request has been black-holed"?
RequestHandlerComponent
BaseAuthenticate
AuthComponent
SecurityComponent
UserModel


How would you express the following SQL condition in CakePHP (>=1.3.x)? "WHERE User.username NOT IN ('jdoe','jsmith','ajones')"
array("NOT"=>array("User.username"=>array('jdoe','jsmith','ajones')))
None of these
array("User.username"=>array("NOT"=>array('jdoe','jsmith','ajones')))
array("User.username NOT IN "=>array('jdoe','jsmith','ajones'))


Which of the following is NOT a View Class in CakePHP?
XML
JSON
Media
XHTML
Themes


Which of the following is NOT a settable parameter used in Media views?
id
extension
name
download
category


Which route only passes integers to the controller action?
Router::connect('/blog/:id', array('controller' => 'blog', 'action' => 'view'), array('pass' => array('id'), 'id' => '[a-z][0-9]+'));
Router::connect('/blog/:id', array('controller' => 'blog', 'action' => 'view'), array('id' => '[0-9]+'));
Router::connect('/blog/:id', array('controller' => 'blog', 'action' => 'view'), array('pass' => array('id'), 'id' => '[0-9]+'));
Router::link('/blog/:id', array('controller' => 'blog', 'action' => 'view'), array('pass' => array('id'), 'id' => '[0-9]+'));


Which of the following is not a way to retrieve data from a model?
(in Model) $this->findAllByActive('true');
(In Model) $this->find('all', array('conditions' => array('active' => true)));
(In ModelController) $this->Model->find('all', array('conditions' => array('active' => true)));
(In ModelController) $this->find('all', array('conditions' => array('active' => true)));


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


Which one below is not a Session configuration option?
Session.terminate
Session.cookie
Session.handler
Session.autoRegenerate
Session.ini


Which of the following is NOT a method that must be implemented for all CRUD methods?
calculate($model, $func, $params)
find('list', $params)
listSources($data = null)
describe($model)


On which layer could you implement your own paginateCount() method?
Helper
Controller
Behavior
DataSource


Which TextHelper method allows you to transform links inside any text to valid HTML link tags?
processLinks()
automaticUrls()
autoLink()
addLinks()


Which of the following is not a built-in validation rule name?
'custom'
'datetime'
'between'
'alphanumeric'
'inList'


Which testing method allows you to test HTML generation easily?
assertHTML()
assertTags()
assertCode()
assertOutput()