Top 50 Zend Framework Interview Questions




Define zend framework and what are the features of zend?

  • Zend framework is an open source and follow MVC pattern.
  • It is used to develop modern web applications.
  • It provides any PHP stack and Zend server to run Zend framework applications.
  • It also provides clean and stable code complete with intellectual property rights and makes programming easier.
  • It is fast, easy to learn and user-friendly framework.
  • It supports strong cryptography tools and password hashing techniques.

The silent features of zend framework are given below:

  • Zend provides RESTful API development support.
  • Flexible URI Routing.
  • Session management.
  • Simple cloud API.
  • Supports multi databases including PostgreSQL, SQLite etc.
  • Pure object oriented web application framework.
  • Advanced MVC implementation.
  • Code reusable and easier to maintain.
  • Data encryption.

Define MVC architecture in Zend?

In zend,MVC stands for model-view-controller,which can separates the application logic from the presentation.
MVC components is as follows:
Model

  • It represents the structure of the application.
  • Model classes contain methods which helps to insert,update and retrieve business data in the database(such as MySQL, PostgreSQL, etc.).

View

  • It is the presentation layer of MVC applications.
  • Using controller,it receives the model data and display it.

Controller

  • It is the main component of MVC architecture.
  • It processes all the request and serves as an intermediary between the Model and View.

What are the componet zend framework provides?

Zend framework provides three types of components,which are given below:
1: Event Manager

It provides ability to create event based programming.
It also helps to create, inject and manage new events.
2: Service Manager:

It provides the ability to consume any services from anywhere with a little effort.
3: Module manager :

It provides the ability to convert a collection of PHP classes with identical functionality into a single unit.
It can be used to maintained and configured as a single unit.

In zend framework,what is the structure of application module?

Zend framework provides a powerful and flexible module system to set up the application accurately.
The application module which is myapp,provides error,bootstrapping and routing configuration to all the application.
The structure of application module is given below:
├── module
│ └── Application
│ ├── config
│ │ └── module.config.php
│ ├── src
│ │ ├── Controller
│ │ │ └── IndexController.php
│ │ └── Module.php
│ ├── test
│ │ └── Controller
│ │ └── IndexControllerTest.php
│ └── view
│ ├── application
│ │ └── index
│ │ └── index.phtml
│ ├── error
│ │ ├── 404.phtml
│ │ └── index.phtml
│ └── layout
│ └── layout.phtml

In Zend framework,define Autoloader?

In zend framework,autoloader is a method which load all the objects on start up.

For zend framework,what services are available from Zend Technologies?

Zend Technologies gives a complete set of services for Zend Framework,which including:
1:Consulting
2:Training
3:Support
4:Certification

In Zend Framework,how Do You Set Module Name, Controller Name, And Action Name?

In zend,Module name is set by $request->setModuleName(‘front’);
Controller name is set by $request->setControllerName(‘address’);
Action name is set by $request->setActionName(‘addresslist’);

In Zend framework,Checking Whether Form Posted Or Not?

Ans:In zend framework,write the below code to check

$request = $this->getRequest();
$_GET = $request->getParams();
$_POST = $request->getPost();

In zend framework,how to fetch last Inserted Id,Fetch All Record And Fetch A Single Record?

In zend framework, using the below code to fetch last Inserted Id,Fetch All Record And Fetch A Single Record

$this->_db->lastInsertId();
$this->_db->fetchAll($sql);
$this->_db->fetchRow($sql);

In Zend framework,what is the basic difference between Zend_registry and Zend_session?

The main difference between Zend_registry and Zend_session is the ‘scope’ in that they are valid:
a:  Zend_Registry : request scope
b:  Zend_Session : session scope
Zend_Registry:

  1. It is used to store objects/values for the ongoing request.
  2. In short,everything which you offend to Registry in index.php can be accessed from other controllers/actions.
  3. Using the Zend_Registry object config parameters and db parameters are normally prepared for global use.

Zend_Session:

  1. It is literally uses PHP sessions.
  2. Using Zend_Session data stored,which can be accessed in different/all pages.
  3. So,if you want to create a variable named ‘UserRole’ in the /auth/login script and want it to be accessible in /auth/redirect, you would use Zend_Session.

In zend framework,when do we need to disable Layout?

In zend framework, we need to disable layout at the time of calling AJAX to obtain.

$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);

In zend framework,define filter?

In zend framework,the Zend_Filter component provides a set of frequently required data filters.
It also provides a smooth filter chaining mechanism by which multiple filters may be applied to a single definition in a user-defined order.

Example:Add an email element

$this->addElement(‘text’, ‘email’, array(
‘label’ => ‘Your email address:’,
‘required’ => true,
‘filters’ => array(‘StringTrim’),
‘validators’ => array(
‘EmailAddress’,
)
));

Other Filters are given bellow:
Alnum – Zend_Filter_Alnum->It is a filter that returns single alphabetic characters and digits.All other characters are supressed.
Alpha – Zend_Filter_Alpha->It is a filter that returns the string $value,removing all but alphabetic characters.
This filter have an option to also grant white space characters.

Describe plugins in zend framework?

1.Front controller events trigger the plugins.
2:Events bookend each major process of front controller.
3:Allowing automating actions which can apply globally in zend framework.
Creating plugins:
a:Extend Zend_Controller_Plugin_Abstract
b:Extend one or more of the event methods.

In zend,how to include css from controller and view?

From within a view file: $this->headLink()->appendStylesheet(‘filename.css’);
From within a controller: $this->view->headLink()->appendStylesheet(‘filename.css’);
And then elsewhere in your layout you need to echo out your headLink object:

Using select query how to protect the site from sql injection in zend framework?

You have to quote the strings,

$this->getAdapter ()->quote ( );
$select->where ( ” = “, );
OR (If you are using the question mark after equal to sign)
$select->where ( ” = ? “, );

In zend framework,how to customize the appearance of forms generated by zend_form.

Here decorators plays a vital role.In zend_form all forms and form elements use decorators to render there output.

17.Q:In zend framework,how to call two different Views from same Action?

Example1:
Public function indexAction() {
If(condition)
$this->render(‘yourview.phtml’);
Else
Index.phtml;
Example2:
Public function indexAction() {
}

Now you can have this statement to call other view in index.phtml file.
$this->action(‘action name’,’controller name’,’module name’,array(‘parameter name’=>’parameter value’));

In zend framework,which version of Php does it require?

PHP 5.2.4 and up version is required for Zend Framework.Few Zend Framework components may work with earlier versions of PHP, but these components are tested and supported only on 5.2.4 and up.

In zend framework how do U define the Library Path?

In zend framework,we have to create directory ‘library’ and place ‘Zend’ directory in it.
The directory structure will look like this
wwwroot
application
lib
Zend
public
index.php

In index.php file you should add the library:

$includePath = array();
$includePath[] = ‘.’;
$includePath[] = ‘./../application’;
$includePath[] = ‘./../library’;
$includePath[] = get_include_path();
$includePath = implode(PATH_SEPARATOR,$includePath);
set_include_path($includePath);

In zend framework,how to include Js from Controller and View in Zend?

From within a view file:

$this->headScript()->appendFile(‘filename.js’);
From within a controller: $this->view->headScript()->appendFile(‘filename.js’);
And then elsewhere in your layout you need to echo out your headScript object:
headScript();

Explain zend engine in php?

  • 1: Zend engine is an open source and is like virtual machine.
  • 2: It is known for automating the web using php.
  • 3: For increasing the php’s popularity,zends reliability performance and extensibility plays a vital role.
  • 4: zend engine is freely available under BSD style licence.
  • 5: Zend gets his name after its developers Zeev and Aandi.

In zend framework,how can you get a module name in Bootstrap File?

In zend framework,to get a module name through the following code:

$router = new Zend_Controller_Router_Rewrite();
$request = new Zend_Controller_Request_Http();
$router->route($request);
$moduleName = $request->getModuleName();

Define routing in zend framework and how it works?

In zend framework,routing is the process of taking a URI endpoint and breake down it into parameters to complete that module, controller, and action of which controller should receive the request.
Zend_Controller_Router_Rewrite is the standard framework router.
When the request is fast received and before the first controller is addressed.
Using pure PHP structures Zend_Controller_Router_Rewrite is create to allow for mod_rewrite-like functionality.
It is also designed to work with a single Apache mod_rewrite rule.

24.Q:In zend framework,how to check post method?

if($this->getRequest()->isPost()){
//Post
}else{
//Not post
}

In zend framework,how to get all post and get data?

In zend framework,to get the post and get data using the below code:

$this->getRequest()->getParams();
$this->getRequest()->getPost();

26.Q:In Zend Framework,how to use update statement?

Ans:class Application_Model_Users extends Zend_Db_Table_Abstract {
protected $_name = 'users';
protected $_primary = 'id';

function updateData($updateData = array()) {
//please update dynamic data
$this->update(array('name' => 'arun', 'type' => 'user'), array('id=?' => 10));
}
}

In Zend Framework,how we can do multiple column ordering?

Ans: class Application_Model_Users extends Zend_Db_Table_Abstract {
protected $_name = 'users';
protected $_primary = 'id';

function users() {
$select = $this->select()
->setIntegrityCheck(false)
->from(array('u' => 'users'), array('name as t_name'))->order('first_name asc')->order('last_name des');
return $this->fetchAll($select);
}

}

What is full form of CLA in Zend Framework?

In zend framework,CLA stands for Contributor License Agreement.

Which Class extend the Zend Controller in zend framework?

In zend framework, zend class extends Zend_Controller_Action class.

Example:class AjaxController extends Zend_Controller_Action {
}

How to get variable’s value from get?

$id= $this->getRequest()->getParam('id');