Saturday, April 30, 2016

Very important CakePHP Descriptive Questions with answers

Posted by Tech Talim

 

1. What is CakePHP? Why use it?

Ans: CakePHP is a free, open-source, rapid development framework for PHP. It’s a foundational structure for programmers to create web applications. Our primary goal is to enable you to work in a structured and rapid manner–without loss of flexibility.
2.  What are the features of Cake PHP?
§  Active, friendly Official CakePHP discussion group
§  Flexible licensing
§  Compatible with versions PHP 5.2.8 and greater
§  Integrated CRUD for database interaction
§  Application scaffolding
§  Code generation
§  MVC architecture
3. What is Model?
The Model layer represents the part of your application that implements the business logic. It is responsible for retrieving data and converting it into meaningful concepts for your application

4. What is View?
The View renders a presentation of modeled data. Being separated from the Model objects, it is responsible for using the information it has available to produce any presentational interface your application might need

5. What is control layer?
The Controller layer handles requests from users. It is responsible for rendering a response with the aid of both the Model and the View layer.

6.  What is AppController class?
the AppController class is the parent class to all of your application’s controllers. AppController itself extends the Controller class included in the CakePHP core library.

7. What are the defferent part of the view layer in Cake PHP?
Ans: views: Views are the part of the page that is unique to the action being run. They form the meat of your application’s response.
elements: smaller, reusable bits of view code. Elements are usually rendered inside views. layouts: view files that contain presentational code that wraps many interfaces in your application. Most views are rendered inside a layout.
helpers: these classes encapsulate view logic that is needed in many places in the view layer

8. What is the purpose of $this->set()?
Function $this->set() in the controller is used to pass variables from the controller to the view

9. 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

10. 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

11. 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.

12. 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.

13. 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.

14. What are commonly used components of cakephp?

Security, Sessions,Access control lists,Emails,Cookies,Authentication,Request handling,Scaffolding

15. 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

16. What are commonly used helpers of cakephp?

FormHelper, HtmlHelper, JsHelper, CacheHelper, NumberHelper, Paginator

17. 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.

18. What is the difference between Component, Helper, Behavior?

Component is a Controller extension, Helpers are View extensions, Behavior is a Model Extension.

19. How to include helpers in controller ?

public $helpers = array(‘Form’, ‘Html’, ‘Js’, ‘Time’);

20. How to include components in controller ?

public $components = array(‘Emails’, ‘ImageUploader’, ‘Sms’);

21. 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’); 

22. What is the use of $this->set(compact());

Using $this->set(compact()) , we can pass multiple parameters to access into the view file.

23. Can you list some database related functions in cakephp?

find, findAll , findAllBy , findBy , findNeighbours and query.

24. 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");

25. How can we use ajax in cakephp?
Ans. By calling ajax helper and then using it in controller for rendering.
Read More

Cake Php MCQ Question for exam

Posted by Tech Talim

1.       What are 3 important parts of MVC?  

A.    The Model represents the application data
B.      The View renders a presentation of model data
C.     Module represents the application part.
D.    The Controller handles and routes requests made by the client
Ans: A, B,D
2.       The view layer in CakePHP can be made up of a number of different parts. What are the different parts of view layer?
A.      View
B.      Element
C.      Controller
D.      Model
E.       Helper
Ans: A, B,E
3.       Which block of the content contains the content of the render view?
A.      Content block
B.      Title Block
C.      Section Block
Ans: A
4.       What are the relationship types in CakePHP?
A.      HasOne
B.      ManytoMany
C.      HasMany
D.      belongsTo
Ans: A,C,D
5.       Cake PHP is a PHP framework package which enables you to develop custom applications. It supports a MVC based architecture.
A.      TRUE
B.      False
Ans: A
6.       what is the first file that gets loaded when you run an application using cakephp.
A.      Index.php
B.      Bootstrap.php
C.      Core.php
D.      Database.php
Ans:  B
7.       What is the first function that gets loaded from a controller?
A.      About
B.      Index
C.      Delete
D.      Edit
Ans: B
8.       What are the lists of some database related functions in cakephp?
A.      Find
B.      FindAll
C.      Create
D.      Query
Ans: A,B,C
9.       What is the name of Cake’s database configuration file?
A.      Datasource
B.      Database
C.      database.php.default
Ans: C
10.   What are commonly used components of cakephp?
A.      Security
B.      Database
C.      Session
D.      Helper
Ans: A,C
11.   CakePHP allows you to set up a combination of controllers, models, and views and release them as a packaged application.
A.      Helper
B.      Plugin
C.      Views
D.      Behavior
Ans: B
12.   Sessions can be configured in a number of ways in CakePHP
A.      $this->Session->write('Person.eyeColor', 'Green');
B.      array('User' => array(  'username' => 'clark-kent@dailyplanet.com'));
C.      'username' => 'clark-kent@dailyplanet.com';
D.      array(  'username' => 'clark-kent@dailyplanet.com'));
Ans: A,B
13.   How to retrieve the session value in CakePHP?
A.      $green = $this->Session->retrieve('Person.eyeColor');
B.      $green = $this->Session->get('Person.eyeColor');
C.      $green = $this->Session->read('Person.eyeColor');
Ans: C

14.   Which method will delete the session cookie and all session data stored in the temporary file system?
A.      Nullable()
B.      destroy()
C.      unset()
Ans: B
15.   In CakePHP, what are the several built-in ways of authenticating users stored in your application.
A.      FormAuthenticate
B.      Da



Read More

Cake PHP Basic Aspects for the exam preparation

Posted by Tech Talim
Chapter-1
ê  naming a table ‘posts’ automatically hooks it to Post model
ê  CakePHP’s database configuration file is found in /app/Config/database.php.default.
ê  The security salt is used for generating hashes. Security.salt location is /app/Config/core.php
ê  The cipher seed is used for encrypt/decrypt strings. Change the default Security.cipherSeed value by editing /app/Config/core.php
ê  The Model class is the bread and butter of CakePHP applications. By naming our model Post, CakePHP can automatically infer that this model will be used in the PostsController, and will be tied to a database table called posts.
ê  Actions often represent a single function or interface in an application.
ê  The link() method will generate an HTML link with the given title (the first parameter) and URL (the second parameter).
ê  $this->request->is() takes a single argument, which can be the request METHOD (get, put, post, delete) or some request identifier (ajax). It is not a way to check for specific posted data. For instance, $this->request->is(’book’) will not return true if book data was posted.
ê  Every CakePHP request includes a CakeRequest object which is accessible using
$this->request
ê  We use the FlashComponent’s FlashComponent::success() method to set a message to a session variable to be displayed on the page after redirection.
ê  FlashHelper::render() which displays the message and clears the corresponding session variable.
ê  To take advantage of the validation features, you’ll need to use CakePHP’s FormHelper in your views.
ê  to generate the opening tag for an HTML form $this->Form->create()
ê  If create() is called with no parameters supplied, it assumes you are building a form that submits via POST to the current controller’s add() action (or edit() action when id is included in the form data).
ê  The $this->Form->input() method is used to create form elements of the same name. The $this->Form->end() call generates a submit button and ends the form.
ê  Validation rules are defined in the model. The $validate array tells CakePHP how to validate data when the save() method is called
ê  Using postLink() will create a link that uses JavaScript to do a POST request to delete our post.
ê  CakePHP’s routing is found in /app/Config/routes.php.
ê  Controller class names are plural, CamelCased, and end in Controller. PeopleController and LatestArticlesController are both examples of conventional controller names.
ê  Model class names are singular and CamelCased. Person, BigPerson, and ReallyBigPerson are all examples of conventional model names.
ê  Table names corresponding456 to CakePHP models are plural and underscored. The underlying tables for the above mentioned models would be people, big_people, and really_big_people, respectively.
ê  View template files are named after the controller functions they display, in an underscored form. The getReady() function of the PeopleController class will look for a view template in /app/View/People/get_ready.ctp.
ê  Controllers callbacks:
• afterFilter(), executed after all controller logic, including the rendering of the view
• beforeFilter(), executed before any controller action logic
• beforeRender(), executed after controller logic, but before the view is rendered
ê  models have callbacks:
• beforeFind()
• afterFind()
• beforeValidate()
• afterValidate()
• beforeSave()
• afterSave()
• beforeDelete()
• afterDelete()
Chapter-3

ê  Model objects can be looked at as the first layer of interaction with any database you might be using for your application.

Chapter-4
ê  a controller is used to manage the logic around a single model
ê  Application’s controllers extend the AppController class, which in turn extends the core Controller class.
ê  The AppController class can be defined in /app/Controller/AppController.php and it should contain methods that are shared between all of your application’s controllers.
ê  CakePHP merges the following variables from the AppController into your application’s controllers:
• $components
• $helpers
• $uses
ê  The conventional view file name is the lowercased and underscored version of the action name.































Read More