Sunday, December 28, 2014

what is class map in zend?

The Class Map Generator utility: bin/classmap_generator.php

Overview

The script bin/classmap_generator.php can be used to generate class map files for use with the ClassMapAutoloader.
Internally, it consumes both Zend\Console\Getopt (for parsing command-line options) and Zend\File\ClassFileLocator for recursively finding all PHP class files in a given tree.

Quick Start

You may run the script over any directory containing source code. By default, it will look in the current directory, and will write the script to autoloader_classmap.php in the directory you specify.
1
php classmap_generator.php Some/Directory/

Configuration Options

–help or -h
Returns the usage message. If any other options are provided, they will be ignored.
–library or -l
Expects a single argument, a string specifying the library directory to parse. If this option is not specified, it will assume the current working directory.
–output or -o
Where to write the autoload class map file. If not provided, assumes “autoload_classmap.php” in the library directory.
–append or -a
Append to autoload file if it exists.
–overwrite or -w
If an autoload class map file already exists with the name as specified via the --output option, you can overwrite it by specifying this flag. Otherwise, the script will not write the class map and return a warning.

how to create a simple album module in zend

Setting up the Album module

Start by creating a directory called Album under module with the following subdirectories to hold the module’s files:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 zf2-tutorial/
     /module
         /Album
             /config
             /src
                 /Album
                     /Controller
                     /Form
                     /Model
             /view
                 /album
                     /album
As you can see the Album module has separate directories for the different types of files we will have. The PHP files that contain classes within the Album namespace live in the src/Album directory so that we can have multiple namespaces within our module should we require it. The view directory also has a sub-folder called album for our module’s view scripts.
In order to load and configure a module, Zend Framework 2 has a ModuleManager. This will look for Module.php in the root of the module directory (module/Album) and expect to find a class called Album\Module within it. That is, the classes within a given module will have the namespace of the module’s name, which is the directory name of the module.
Create Module.php in the Album module: Create a file called Module.php under zf2-tutorial/module/Album:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 namespace Album;

 use Zend\ModuleManager\Feature\AutoloaderProviderInterface;
 use Zend\ModuleManager\Feature\ConfigProviderInterface;

 class Module implements AutoloaderProviderInterface, ConfigProviderInterface
 {
     public function getAutoloaderConfig()
     {
         return array(
             'Zend\Loader\ClassMapAutoloader' => array(
                 __DIR__ . '/autoload_classmap.php',
             ),
             'Zend\Loader\StandardAutoloader' => array(
                 'namespaces' => array(
                     __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
                 ),
             ),
         );
     }

     public function getConfig()
     {
         return include __DIR__ . '/config/module.config.php';
     }
 }
The ModuleManager will call getAutoloaderConfig() and getConfig() automatically for us.

Autoloading files

Our getAutoloaderConfig() method returns an array that is compatible with ZF2’s AutoloaderFactory. We configure it so that we add a class map file to the ClassMapAutoloader and also add this module’s namespace to the StandardAutoloader. The standard autoloader requires a namespace and the path where to find the files for that namespace. It is PSR-0 compliant and so classes map directly to files as per the PSR-0 rules.
As we are in development, we don’t need to load files via the classmap, so we provide an empty array for the classmap autoloader. Create a file called autoload_classmap.php under zf2-tutorial/module/Album:
1
 return array();
As this is an empty array, whenever the autoloader looks for a class within the Album namespace, it will fall back to the to StandardAutoloader for us.
Note
If you are using Composer, you could instead just create an empty getAutoloaderConfig() { } and add to composer.json:
1
2
3
 "autoload": {
     "psr-0": { "Album": "module/Album/src/" }
 },
If you go this way, then you need to run php composer.phar update to update the composer autoloading files.

Configuration

Having registered the autoloader, let’s have a quick look at the getConfig() method in Album\Module. This method simply loads the config/module.config.php file.
Create a file called module.config.php under zf2-tutorial/module/Album/config:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
 return array(
     'controllers' => array(
         'invokables' => array(
             'Album\Controller\Album' => 'Album\Controller\AlbumController',
         ),
     ),
     'view_manager' => array(
         'template_path_stack' => array(
             'album' => __DIR__ . '/../view',
         ),
     ),
 );
The config information is passed to the relevant components by the ServiceManager. We need two initial sections: controllers and view_manager. The controllers section provides a list of all the controllers provided by the module. We will need one controller, AlbumController, which we’ll reference as Album\Controller\Album. The controller key must be unique across all modules, so we prefix it with our module name.
Within the view_manager section, we add our view directory to the TemplatePathStack configuration. This will allow it to find the view scripts for the Album module that are stored in our view/ directory.

Informing the application about our new module

We now need to tell the ModuleManager that this new module exists. This is done in the application’s config/application.config.php file which is provided by the skeleton application. Update this file so that its modules section contains the Album module as well, so the file now looks like this:
(Changes required are highlighted using comments.)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
 return array(
     'modules' => array(
         'Application',
         'Album',                  // <-- Add this line
     ),
     'module_listener_options' => array(
         'config_glob_paths'    => array(
             'config/autoload/{,*.}{global,local}.php',
         ),
         'module_paths' => array(
             './module',
             './vendor',
         ),
     ),
 );
As you can see, we have added our Album module into the list of modules after the Application module.
Step create using command : zf.php create module modulename (or zf2.php if using zf2).

Tuesday, November 18, 2014

how to get CKeditor value using javascript[Solve]

<script jang="javascript">

var xvalue=CKEDITOR.instances['myTextarea'].getData();

alert(xvalue);

</script>

Thursday, November 13, 2014

how to search one view used in other views in oracle?

SELECT * FROM User_Dependencies
WHERE TYPE IN
('PACKAGE',
'PACKAGE BODY', 'TYPE BODY',
'TRIGGER',
'FUNCTION',
'VIEW',
'SYNONYM',
'TYPE'
)
AND REFERENCED_OWNER = 'SERVERDB'
AND REFERENCED_NAME = 'SERVERS_V';


What main different between session and cache?

The first main difference between session and caching is: a session is per-user based but caching is not per-user based, So what does that mean? Session data is stored at the user level but caching data is stored at the application level and shared by all the users. It means that it is simply session data that will be different for the various users for all the various users, session memory will be allocated differently on the server but for the caching only one memory will be allocated on the server and if one user modifies the data of the cache for all, the user data will be modified.

Tuesday, November 11, 2014

zend framework interview questions and answers for experienced

Question: How to disable layout from controller?

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


Disable Zend Layout from controller for Ajax call only
?
1
2
3
if($this->getRequest()->isXmlHttpRequest()){
    $this->_helper->layout()->disableLayout();
}


How to change the View render file from controller?
?
1
2
3
4
function listAction(){
    //call another view file file
    $this->render("anotherViewFile");
}


How to protect your site from sql injection in zend when using select query?
?
1
2
3
4
5
$select = $this->select()               
                ->from(array('u' => 'users'), array('id', 'username'))
                ->where('name like ?',"%php%")
                ->where('user_id=?','5')
                ->where('rating<=?',10);



How to check post method in zend framework?
?
1
2
3
4
5
if($this->getRequest()->isPost()){
    //Post
}else{
//Not post
}


How to get all POST data?
?
1
$this->getRequest()->getPost();


How to get all GET data?
?
1
$this->getRequest()->getParams();


How to redirect to another page from controller?
?
1
$this->_redirect('/users/login');


How to get variable's value from get?
?
1
$id= $this->getRequest()->getParam('id');


Create Model file in zend framework?
?
1
2
3
4
class Application_Model_Users extends Zend_Db_Table_Abstract {
    protected $_name = "users";
    protected $_primary = "id";     
}


How to create object of Model?
?
1
$userObj = new Application_Model_Users();


Which Class extend the Zend Controller?
Zend_Controller_Action
For Example
?
1
2
class AjaxController extends Zend_Controller_Action {
}


Which Class extend the zend Model?
Zend_Db_Table_Abstract
For Example
?
1
class Application_Model_Users extends Zend_Db_Table_Abstract { }


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


Why should we use framework?
Framework is a structured system where we get following things
Rapid application development(RAD).
Source codes become more manageable.
Easy to extend features.


Where we set configuration in zend framework?
We set the config in application.ini which is located in application/configs/application.ini.


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.


What is full form of CLA in Zend Framework?
Contributor License Agreement


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.


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 somewhere in your layout you need to echo out your headScript object: $this->headScript();


What are Naming Convention for PHP File?
1. There should not any PHP closing tag (?>)in controller & Model file.
2. Indentation should consist of 4 spaces. Tabs are not allowed.
3. The target line length is 80 characters, The maximum length of any line of PHP code is 120 characters.
4. Line termination follows the Unix text file convention. Lines must end with a single linefeed (LF) character. Linefeed characters are represented as ordinal 10, or hexadecimal 0x0A


What are Naming Convention for Classes, Interfaces, FileNames, Functions, Methods, Variables and constants?
http://framework.zend.com/manual/1.11/en/coding-standard.naming-conventions.html


What are coding style of Zend Framework?
http://framework.zend.com/manual/1.12/en/coding-standard.coding-style.html


What is Front Controller in Zend Framework?
Zend used Front Controller pattern for rendering the data. It 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.

How to use update statemnet in Zend Framework?
?
1
2
3
4
5
6
7
8
9
  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));
    }
}


How we can do multiple column ordering in Zend Framework?











  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);
    }
  
}

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

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 ( " = ? ", );