Showing posts with label Cakephp Interview Questions. Show all posts
Showing posts with label Cakephp Interview Questions. Show all posts

Monday 26 October 2015

CakePHP Interview Questions and Answers for experienced

CakePHP Interview Questions and Answers for experienced



Question: What Is The Current Stable Version Of CakePHP?
3.1.1 / 6 October 2015

Question: What are the System requirement for cakephp3.0
PHP 5.4.16 or greater.
mbstring extension
intl extension
MySQL (5.1.10 or greater)


Question: What Is The Name Of Cakephp Database Configuration File Name And Its Location
FileName: database.php.default
Location: /app/config/database.php.default


Question: What is First cakphpe file loaded in application?
bootstrap.php
Also, We can change its file through index.php file which loaded earlier.


Question: What Is The Use Of Security.Salt And Security.CipherSeed In Cakephp?
The Security.salt is used for generating hashes.
The Security.cipherseed is used for encrypt/decrypt strings.
You can change the above values from /app/Config/core.php.

Question: What Is Default Function For A Controller?
index() function


Question: Which Function Is Executed Before Every Action In The Controller?
beforeFilter() function


Question: List Some Of The Features In CakePHP?
  1. MVC architecture
  2. Built-in validations
  3. Caching
  4. Scaffolding
  5. Auth & ACL
  6. CSRF protection via Security Component.


Question: What Is Scaffolding In Cakephp?
Scaffolding is a technical way that allows a developer to define and create a basic application that can create, retrieve, update and delete objects.


Question: How To Add Scaffolding In Your Application?
var $scaffold;
Add above In Controller Question: What Is A Behavior?
Behaviors in CakePHP are associated with Models.


Question: How To Include Components In Controller?
public $components = array('Emails', 'ImageUploader');


Question: What is callback functions in Cakephp? Please explain?
Callback functions are simple functions which called automatically when are defined by the core cakephp.
Suppose you are inserting record in your database. Now you have two requirement.
1. Validate the data before inserting into database.
2. Want to do some changes after inserting into database.


Question: How callback functions works in CakePHP?
/** In controller**/
$userData = array();
$this->User->InsertRecord($userData );
/** In controller**/

/** In model **/
function InsertRecord($userData){
    $this->save($userData);
}

function beforeSave(){
}

function AfterSave(){
}
/** In model **/



Question: What are associations in CakePHP? What are different types of associations?
Associations are the terms which means getting the data from database which are in different tables.


Relationship Association Type Example in Single Line
one to one hasOne A user has one profile.
one to many hasMany A user can have multiple recipes.
many to one belongsTo Many recipes belong to a user.
many to many hasAndBelongsToMany Recipes have, and belong to, many ingredients.

When Models's save function going to called, beforeSave will be called then AfterSave.




Question: How To Get Current URL In CakePHP?
echo $this->here;

Question: Which Methods Are Used To Create And Destroy Model Associations?
bindModel() used to create Model Associations
unbindModel() used to destroy Model Associations


Question: What Is The Use Of RequestAction Method?
Its used to a call controller action from any location and returns data from the that action.


Question: How Can We Use Ajax In Cakephp?
Use ajax helper.


Question: What Is The Default Extension Of view files In Cakephp?
.ctp



Question: What Is folder structure of cakePHP?
What Is folder structure of cakePHP




Question: How to set Meta title from view files?
$this->set("title_for_layout", "This is page meta title");




Wednesday 12 June 2013

Difference Between Cakephp and Zend Framework

S.No Cakephp Zend Framewok
1
It is just framework. It is Both framework and library.
2
In View Form helper, there is form elements, validation available. In View Form helper, there is form elements, validation, filters(like strip_tags), order of elements, sub form, and decoraters are available.
3
we can render form elements one by one We can render form in one line, one by one element, element OR  decorator OR error separetly.
4
Form configuration can not done by through configuation file Zend_form can be do configuration through zend_cofig or xml
5
When cake start, It load all library that's why Its not good for small project. Its library is too big as compare to cakephp. If you are  not using any component then it will not load by default.
6
It uses front controller design and singleton design pattern. It use front controller pattern, factory patter, strategy pattern, singleton pattern.
7
It is good for fast development. It is best, if you application are using webservices
8
ACL, Auth like comonents are easily availbele for cakephp. It has its own ACL, Auth components and upto deeper level.
9
When cake start, It load all library that's why Its not good for small project. Its library is too big as compare to cakephp. If you are  not using any component then it will not load by default.
10
It have session component It have Zend Session and Zend Registery components.
11
Its class name does not map with file location Its mapping,
If any class name is Zend_forms_abc
file location is Zend/Forms/abc.php
12
Mostly used for fast development. Mostly used for web services

Saturday 8 June 2013

Pending Interview Questions and Answers

Who is the Father of PHP?
Rasmus Lerdorf


Which programming language does PHP resemble to?
PHP resemble to pearl and C


How can we create a database using PHP and MySQL?
We can create MySQL database in php with the use of
mysql_create_db ("db_name");


Is variable name case sensitive?
Yes, In PHP variable name case sensitive. We cannot start a variable with number like $777name as a valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.


How can we execute a php script using command line?
Just run the PHP CLI (Command Line Interface) program and provide the PHP script file name as the command line argument. For example, "php myScript.php", assuming "php" is the command to invoke the CLI program.


Differentiate between in_array() and array_search() in php?
in_array : Checks if a value exists in an array. array_search() : Searches an array for a given value and returns the corresponding key if successful.


How do you call a constructor for a parent class?
parent::constructor($value);


How to delete file in PHP ?
unlink($filename);


How to delete variable in PHP ?
unset($variable);


What is the urlencode and urldecode in php ?
Returns a string in which all non-alphanumeric characters except -_. have been replaced with a percent (%) sign followed by two hex digits and spaces encoded as plus (+) signs.


What is the use of the function htmlentities?
htmlentities Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.


Differentiate between strstr and stristr in php?
strstr() and stristr both are used to find the first occurence of the string only difference is stristr( ) is case insensitive.


How can we know the total number of elements of Array?
sizeof($array);
count($array);


How to secure your website?
  1. Validate Input.
  2. Use Auth & ACL.
  3. Protect my Session ID
  4. Preventing Cross Site Scripting (XSS) flaws
  5. SQL injection vulnerabilities
  6. Turning off error reporting and exposing to the site for hackers
  7. Protect secure data of website


What is PHP configuration file called?
php.ini.


What is a persistent cookie?
A persistent cookie is a cookie which is stored in a cookie permanently on the browser's computer. By default, cookies are created as temporary cookies which stored only in the browser's memory. When the browser is closed, temporary cookies will be erased automatically.


What are non-key columsn in database?
Answer: A non key attribute in sql server is a columns which can not be used to identify a record uniquely for example name or age columns in customer table


Sunday 21 April 2013

Cakephp Interview Questions and Answers

Question: What is  cakephp?.
Answer: 
CakephpCakePHP  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



Question: When CakePHP was developed?
April 2005


Question: What is current Stable version of cakePHP?
3.1.5 / 30 November 2015


Question: For cakPHP 3.1.5 installtion, what is minimum PHP Version required?
PHP 5.4


Question: 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.

Question : 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


Question : 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"


Question : 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).


Question : 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


Question: What is HABTM.
Answer: Full form of Has And Belongs To Many.
It is a kind of associations that can be defined in models for retrieving associated data across different entities.
For Example
A product have one or more tags, and a tag may belongs to one or more product.


HABTM Relation

/**
 * Post Model
 *
 * @property Tag $Tag
 */
class Post extends AppModel {

/**
 * Display field
 *
 * @var string
 */
 public $displayField = 'name';

/**
 * Validation rules
 *
 * @var array
 */
 public $validate = array( );

/**
 * hasAndBelongsToMany associations
 *
 * @var array
 */
 public $hasAndBelongsToMany = array(
  'Tag' => array(
   'className' => 'Tag',
   'joinTable' => 'posts_tags',
   'foreignKey' => 'post_id',
   'associationForeignKey' => 'tag_id',
   'unique' => 'keepExisting',
  )
 );

 
}

Question : What is default function and default controller of cakephp which is called automatically?
Answer: Default controller is indexController.php and Default function is index.


Question : How cakephp URL looks in address bar
Answer: http://example.com/controller/action/param1/param2/param3

Question : Why cakephp have two vendor folder?
Answer: There is two vendor folder, one folder in root and another is in "app" folder




    Question : List some database related functions in cakephp.
    Answer: find, findAll , findAllBy , findBy , findNeighbours and query.


    Question : 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 multiple tasks. Included shells: bake, schema, acl, i18 extractor, api.
    • CSRF protection via Security Component.
    • HTTP Authentication via Security Component.
    • Flexible Caching: use memcache, apc, xcache, the file system, or a model to speed up your application
    • Configure class to provide dynamic handling of configuration settings and App class to handle importing required classes.
    • Now Supports Unit Testing application.
    • Integration with Crusecontrol and Ant.



    Question : list some of the features in Cakephp
    Answer: Following are some feature of Cakephp.
    MVC architecture
    Built-in validations
    Caching
    scaffolding




    Saturday 30 June 2012

    Cakephp Layout - How to set Layout


    A layout contains presentation code that wraps around a view. Anything you want to see in all of your views should be placed in a layout.
    Layout files should be placed in /app/views/layouts. CakePHP's default layout can be overridden by creating a new default layout at /app/views/layouts/default.ctp. Once a new default layout has been created, controller-rendered view code is placed inside of the default layout when the page is rendered.
    When you create a layout, you need to tell CakePHP where to place the code for your views. To do so, make sure your layout includes a place for $content_for_layout (and optionally, $title_for_layout).





    Example is below

    <html>
    <head>
    <!-- Include external files and scripts here (See HTML helper for more info.) -->
    <?php echo $scripts_for_layout ?>
    <title>
    <?php echo $title_for_layout ?>
    </title>
    </head>
    <body>
    <?php echo $content_for_layout ?>
    </body>
    </html>
    



    Tuesday 6 September 2011

    Multilingual in Cakephp1.3

    Multilingual in cakephp
    Just do the following three points

    1) In view file user as
    echo __('USERNAME'); 

    2) IN default.po locale/eng/LC_MESSAGES/default.po
    msgid "USERNAME" 
    msgstr "User Name"

    3) // config/bootstrap.php
    define(DEFAULT_LANGUAGE, 'eng');
    

    4)In HTML head add Following
    [meta charset="UTF-8"]

    Compile .po file
    msgfmt message.po.txt -o message.po 




    Multilingual Characters save in Database
    1. Table Collation should be utf8_general_ci
    2. Table's Field Collation should be utf8_general_ci
    3. While Save in Db, set character set utf8
    4. When Display in Browser, add following tag in Head
    <meta charset="UTF-8">