Friday, 12 January 2018

Zend Framework 2 Routes Tutorial

Zend Framework 2 Routes Tutorial

Question: What is routing?
Routing is the act of matching a request to a given controller.



Question: What are different type of routing?
Following are different type of routing
  1. Literal literal route is one that matches a specific string. In this one rule match to one
  2. Segment A segmented route is used for whenever your url is supposed to contain variable parameters. parameters are used to identify certain objects within your application.



Question: Give example of Literal route?
For Example:
http://domain.com/about-me
http://domain.com/contact-us
http://domain.com/terms

    'router' => array(
        'routes' => array(
        'staticpages1' => array(
             'type' => 'literal',
             'options' => array(
                 'route'    => '/about-me',
                 'defaults' => array(
                     'controller' => 'Album\Controller\Album',
                     'action'     => 'aboutme',
                 ), 
             ),
         ),            
        'staticpages2' => array(
             'type' => 'literal',
             'options' => array( 
                 'route'    => '/contactus',
                 'defaults' => array(
                     'controller' => 'Album\Controller\Album',
                     'action'     => 'contactus',
                 ),
                
             ),
         ),            
        'staticpages3' => array(
             'type' => 'literal',
             'options' => array(
                 'route'    => '/terms',
                 'defaults' => array(
                     'controller' => 'Album\Controller\Album',
                     'action'     => 'terms',
                 ),
             ),
         ), 
        ),
    ),



Question: Give example of Segment route?
For Example: http://domain.com/album
http://domain.com/album/add
http://domain.com/album/edit/1
http://domain.com/album/delete/1


    'router' => array(
        'routes' => array(
            'album' => array(
                'type' => 'segment',
                'options' => array(
                    'route' => '/album[/:action][/:id]',
                    'constraints' => array(
                        'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
                        'id' => '[0-9]+',
                    ),
                    'defaults' => array(
                        'controller' => 'Album\Controller\Album',
                        'action' => 'index',
                    ),
                ),
            ),
        ),
    ),



Question: What is database abstraction layer?
A database abstraction layer is a simplified "representation of a database" in the form of a written description or a diagram.

There are 3 abstraction layers:
  1. User model
  2. Logical Model
  3. Physical Model



Question: Why we should use database abstraction?
Once after the application development with MySQL, there is requirement to change the internal database from MySQL to SQL.
IF we have developed application with database abstraction, then we need to change the interface only.
IF we have not developed application with database abstraction, then we need to update re-write the code.