1. What is a framework?

In software development, a framework is a defined support structure in which another software project can be organized and developed.

=> An abstract design

=> Set of common functionalities

=> Developed for a particular domain

 

2. Why should we use a framework?

A framework is a structured system:

=> Source codes become more manageable

=> Easy to extend features

=> Rapid application development

 

3. Configuration in Zend Framework, application.ini file?

Configuration can be done in the application.ini file in the Zend framework. This file is in the path application/configs/application.ini.

 

4. Checking whether form posted or not in Zend framework?

$request = $this->getRequest();

$_GET = $request->getParams();

$_POST = $request->getPost();

 

5. Does Zend Framework support PHP 4?

No. Zend Framework was built to use all of the sophisticated object oriented features of PHP 5 and take advantage of significant performance and security enhancements.

 

6. What is Bootstrapping?

Many PHP applications funnel server requests into a single (or few) PHP source file that sets up the environment and configuration for the application, manages sessions and caching, and invokes the dispatcher for their MVC framework. They can do more, but their main job is to take care of the consistent needs of every page of a web application. 

In our Blueprint for PHP Applications, we will have a core bootstrapper that receives all dynamic requests for an application and applies a template for application behavior that we can later extend. It will allow us to later customize the functionality for each unique application. 

 

7. What is zend engine?

Zend Engine is used internally by PHP as a complier and runtime engine. PHP Scripts are loaded into memory and compiled into Zend opcodes.

 

8. What is zend engine in PHP?

Zend engine is like a virtual machine and is an open source, and is known for its role in automating the web using PHP. Zend is named after its developers Zeev and Aandi. Its reliability, performance and extensibility has a significant role in increasing the PHP’s popularity. The Zend Engine II is the heart of PHP 5. It is an open source project and freely available under BSD style license. 

 

9. what is routing and how it's work?

Zend_Controller_Router_Rewrite is the standard framework router. Routing is the process of taking a URI endpoint (that part of the URI which comes after the base URL) and decomposing it into parameters to determine which module, controller, and action of that controller should receive the request. This values of the module, controller, action and other parameters are packaged into a Zend_Controller_Request_Http object which is then processed by Zend_Controller_Dispatcher_Standard. Routing occurs only once: when the request is initially received and before the first controller is dispatched.

Zend_Controller_Router_Rewrite is designed to allow for mod_rewrite-like functionality using pure PHP structures. It is very loosely based on Ruby on Rails routing and does not require any prior knowledge of webserver URL rewriting. It is designed to work with a single Apache mod_rewrite rule.

 

10. What are Plugins in zend framework?

• Triggered by front controller events

• Events bookend each major process of the front controller

• Allow automating actions that apply globally

 

Creating Plugins:

• Extend Zend_Controller_Plugin_Abstract

• Extend one or more of the event methods 

 

11. Zend_Cache provides a generic way to cache any data.

Caching in Zend Framework is operated by frontends while cache records are stored through backend adapters (File, Sqlite,Memcache...) through a flexible system of IDs and tags. Using those, it is easy to delete specific types of records afterwards (for example: "delete all cache records marked with a given tag"). 

The core of the module (Zend_Cache_Core) is generic, flexible and configurable. Yet, for your specific needs there are cache frontends that extend Zend_Cache_Core for convenience: Output, File, Function and Class. 

 

12. Difference between Zend_Registry and Zend_Session?

The basic difference between these objects is the ‘scope’ in which they are valid:

a) Zend_Registry : request scope

b) Zend_Session : session scope

a) Zend_Registry is used to store objects/values for the current request. In short, anything that you commit to Registry in index.php can be accessed from other controllers/actions (because EVERY request is first routed to the index.php bootstrapper via the .htaccess file). Config parameters and db parameters are generally prepped for global use using the Zend_Registry object.

b) Zend_Session actually uses PHP sessions. Data stored using Zend_Session can be accessed in different/all pages. 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.

 

13. When do we need to disable layout?

At the time of calling AJAX to fetch we need to disable layout.

$this->_helper->layout()->disableLayout();

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

 

14. Where is the model in ZF’s MVC implementation?

The model component can vary dramatically in responsibilities and data store from one MVC application to the next.

 

15. 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 in your index.phtml you can have this statement to call other view

$this->action(‘action name’,’controller name’,’module name’,array(‘parameter name’=>’parameter value’));

 

16. How to include css from controller and view in zend

From within a view file: $this->headLink()->appendStylesheet(‘filename.css’);

From within a controller: $this->view->headLink()->appendStylesheet(‘filename.css’);

And then somewhere in your layout you need to echo out your headLink object:

<?=$this->headLink();?>

 

17. How do you protect your site from sql injection in zend when using select query?

You have to quote the strings,

$this->getAdapter ()->quote ( <variable name> );

$select->where ( ” <field name> = “, <variable name> );

OR (If you are using the question mark after equal to sign)

$select->where ( ” <field name> = ? “, <variable name> );

 

18. What is MVC?

=> Model-View-Controller development pattern.

=> MVC is a software approach that separates application logic from presentation.

Model: The "stuff" you are using in the application data, – web services, feeds.

View : The display returned to the user.

Controller: Manages the request environment, and determines what happens.

 

19. Features of MVC in Zend Framework?

• Declare custom routing rules

Not limited to “controller/action/param” format

• Optional Controller Plugins, Action Helpers, and View Helpers

ErrorHandler plugin handles exceptions, 404 errors, etc.

FlashMessenger, Redirector, ViewRenderer helpers

Output common HTML elements in views

• Extensible interfaces

Write your own plugins and helpers

 

20. Why can't Zend_Form render my File element without errors?

The file element needs a special file decorator, which is added by default. When you set your own decorators for file elements, you delete the default decorators. 

For example:

$element->setDecorators(array(

    array('ViewHelper'),

    array('Errors')

));

You should use a File decorator instead of the ViewHelper for the file element, like so:

$element->setDecorators(array(

    array('File'),

    array('Errors')

));

 

21. How can I customize the appearance of forms generated by Zend_Form?

You're probably looking for decorators. All forms and form elements in Zend_Form use decorators to render their output. 

 

22. Why does the Zend Framework project have a CLA at all?

The CLA protects all users including individuals, small and medium businesses, and large corporations. By having a CLA in place, we mitigate the risk that companies who claim intellectual property infringement may demand royalties or fees from users of Zend Framework, whether individuals or companies. This is especially important for companies basing their business or products on Zend Framework. The Zend Framework CLA helps to ensure that code and other IP in Zend Framework remains free. 

 

23. Should I sign an individual CLA or a corporate CLA?

If you are contributing code as an individual- and not as part of your job at a company- you should sign the individual CLA. If you are contributing code as part of your responsibilities as an employee at a company, you should submit a corporate CLA with the names of all co-workers that you foresee contributing to the project.

 

24. What is Front Controller?

It used Front Controller pattern.  zend also use singleton pattern.

=> routeStartup: This function is called before Zend_Controller_Front calls on the router to evaluate the request.

=> routeShutdown: This function  is called after the router finishes routing the request.

=> dispatchLoopStartup: This is called before Zend_Controller_Front enters its dispatch loop.

=> preDispatch: called before an action is dispatched by the dispatcher.

=> postDispatch: is called after an action is dispatched by the dispatcher. 

 

25. Where's the model?

Unlike the view and the controller components, the model component can vary dramatically in responsibilities and data storage from one MVC application to the next. It should represent what your application does in the abstract. The Zend Framework community has not defined a model interface, class, or other formalism because we haven't identified enough added value to justify limitations on what constitutes a model.

 

26. I want to use a SQL function or perform calculations in a statement I'm generating with Zend_Db_Select. How can I do this?

Actually, by default, if your expression includes parentheses, Zend_Db_Select will cast the statement appopriately. However, if it does not, or you are having problems, you can useZend_Db_Expr to explicitly create the expression:

* Build the SQL:

* SELECT p."product_id", p.cost * 1.08 AS cost_plus_tax

* FROM "products" AS p

*/

$select = $db->select()

->from(array('p' => 'products'),

array(

'product_id',

'cost_plus_tax' => new Zend_Db_Expr('p.cost * 1.08'),

));

 

27. What is the difference between Zend_Auth and Zend_Acl? 

Zend_Auth is used for authenticating users with a variety of authentication methods, including LDAP, OpenID, and HTTP. Authentication is the process of verifying that the provided credentials are valid for the system. By authenticating to your system, your users can prove that they are who they say they are. For more information on Zend Framework's authentication implementation, see the Zend_Auth documentation.

           Zend_Acl is an implementation of Access Control List (ACL) authorization. Generally speaking, ACLs are lists of roles that are authorized to perform a particular operation on specific resources in your system. Zend_Acl can support advanced rule definitions with features such as multiple inheritance for roles and assertions for conditional rules. For more information on Zend_Acl, see the Zend_Acl documentation.

            Zend_Auth and Zend_Acl can be used together to build very sophisticated security systems: first the user confirms their identity with Zend_Auth, then this identity is used to assign one or more Zend_Acl roles to the user for authorization to use or modify resources in the system 

 

28. What is this "username" I have to submit with my CLA, and why do I have to submit it?

This is the username you use to access the issue tracker, wiki, code browser, etc. If you don't have a username yet, you can sign up here.

When we process your CLA, we need to grant the appropriate privileges to your user. To do this, we need to know your username. 

 

28. Should I sign an individual CLA or a corporate CLA?

If you are contributing code as an individual- and not as part of your job at a company- you should sign the individual CLA. If you are contributing code as part of your responsibilities as an employee at a company, you should submit a corporate CLA with the names of all co-workers that you foresee contributing to the project.

 

29. What should I know about the Zend Framework CLA before submitting it?

By signing a CLA, the person contributing source code provides a copyright license to Zend to use the source code he or she submitted to the Zend Framework project. By doing so, the contributor does not give up his or her own rights or copyright to his or her own code, but provides us with a copyright license. In addition, the purpose of the CLA is to clearly define the terms under which intellectual property has been contributed to Zend Framework and to make sure that, to the best of the contributor's knowledge, he or she is entitled to make such contribution and is not violating anyone else's intellectual property.

 

30. Why does the Zend Framework project have a CLA at all?

The CLA protects all users including individuals, small and medium businesses, and large corporations. By having a CLA in place, we mitigate the risk that companies who claim intellectual property infringement may demand royalties or fees from users of Zend Framework, whether individuals or companies. This is especially important for companies basing their business or products on Zend Framework. The Zend Framework CLA helps to ensure that code and other IP in Zend Framework remains free. 

 

31. I am a minor (under 18 years of age). Who should sign my CLA?

CLA's for contributors under the age of 18 should be signed by both the contributor and the contributor's legal guardian. 

I want to use a SQL function or perform calculations in a statement I'm generating with Zend_Db_Select. How can I do this?

/* Build the SQL:

 * SELECT p."product_id", p.cost * 1.08 AS cost_plus_tax

 * FROM "products" AS p

 */

$select = $db->select()

        ->from(array('p' => 'products'),

               array(

                   'product_id',

                   'cost_plus_tax' => new Zend_Db_Expr('p.cost * 1.08'),

                ));

 

32. How can I customize the appearance of forms generated by Zend_Form?

You're probably looking for decorators. All forms and form elements in Zend_Form use decorators to render their output. 

 

33. How can I add extra HTML (such as a link) to my form element?

This can easily be done using decorators. For instance using the Description decorator. It is important to note though that you will need to turn off escaping for the output of the decorator:

$element->setDecorators(array(

    array('ViewHelper'),

    array('Description', array('escape', false)),

    array('Errors'),

    array('HtmlTag', array('tag' => 'dd')),

    array('Label', array('tag' => 'dt')),

));

Now, you can use the following to add extra HTML to the element:

$element->setDescription('<strong>This contains HTML that will actually be parsed by the browser, not escaped</strong>');

 

34. Why can't Zend_Form render my File element without errors?

The file element needs a special file decorator, which is added by default. When you set your own decorators for file elements, you delete the default decorators. For example:

$element->setDecorators(array(

    array('ViewHelper'),

    array('Errors')

));

You should use a File decorator instead of the ViewHelper for the file element, like so:

$element->setDecorators(array(

    array('File'),

    array('Errors')

));

 

35. How can I detect if an optional file has been uploaded?

The receive() method will return true for file elements that are not required. The reason is that you said "the file can be omitted, and that's ok for me". The receive() method will return false only in the event of a failure.

Still there are several ways to detect if a file has been uploaded or not:

    Use isUploaded which returns a boolean

    Use getFileName which returns null in this case (note that you must use the latest release for this behaviour)

    Use getFileInfo which will have an empty 'file' key and the flag 'isUploaded' set to false