ZF is both. Zend Framework provides all the components required for most web applications in a single distribution. But Zend Framework components are also loosely coupled, making it easy to use just a few components in a web application- even alongside other frameworks! Using this use-at-will architecture, we are implementing features commonly found in more monolithic frameworks. In fact, we are currently working on a tooling component for the 1.8 release that will make it simpler to build applications using ZF components, yet will not sacrifice the use-at-will nature of existing ZF components.
What is autoloader?
Autoloader is function that load all the object on start up.
What is use of Zend front controller?
Routing and dispatching is managed in the front controller. It collects all the request from the server and handles it.
What is the use of Bootstrap?
Apart from index if we want to do any extra configuration regarding database and other things that is done within bootstrap.
How you can set Module name, Controller name, and Action name in Zend framework?
- $request->setModuleName(‘front’);
- $request->setControllerName(‘address’);
- $request->setActionName(‘addresslist’);
Configuration in Zend Framework, application.ini file?
Configuration can be done in application.ini file in Zend framework. This file in the path application/configs/application.ini.
Checking whether form posted or not in Zend framework?
$request = $this->getRequest();
$getData = $request->getParams();
$postData = $request->getPost();
$isPost = $request->isPost();
Fetch last inserted id, fetch all record,find and fetch a single record.
$this->_db->lastInsertId();
$this->_db->fetchAll($sql);
Fetch last inserted id, fetch all record,find and fetch a single record.
$this->_db->lastInsertId();
$this->_db->fetchAll($sql);
$this->_db->find($id);
$this->_db->fetchRow($sql);
Difference between Zend_Registry and Zend_Session?
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.
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.
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);
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’));
Can we call a model in view?
Yes, you can call a model in view. Simple create the object and call the method.
$this->_db->fetchRow($sql);
Difference between Zend_Registry and Zend_Session?
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.
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.
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);
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’));
Can we call a model in view?
Yes, you can call a model in view. Simple create the object and call the method.
$modelObj = new Application_Model_User();
Can we rename the application folder ?
yes, we can
Can we move the index.php file outside the public folder?
yes, we can
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();?>
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();?>
How do you protect your site from sql injection in zend when using select query?
We 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> );
What is zend framework?
Answer: It is opensource framework created by zend.com (PHP company). It is object oriented and follow the MVC. Zend Framework is focused on building more secure, reliable and fast development.
How to add extra HTML (i.e link) in Zend_Form?
Answer: use Desciption decorator with (escape =false in second parameter).
How can I detect if an optional file has been uploaded?
Answer: Zend_File_Transfer_Adapter_Http's receive() return true.
What is Zend registry?
Answer: It is container for object and values in applications, when you set an object in zend_registry you can access in whole site.
What is Zend_Form?
Answer: It is mainly used to display the form. but along with this we use for filter, validation and formating our form. It have following elements
Element filter
Element validation
Element ordering.
Decorator
Grouping
Sub form
Rendering form elments in single call or one by one for elements.
What is zend helpers?
It can be divided in two parts,
a) Action Helper: the helper is created for controller
b) View Helper: the helper is created for view files (.phtml).
What do you know about zend layout.
Answer: It work as a site template and have following features.
Automatic selection and rendering layout
Provide separate scope for calling element i.e parital, render, partialLoop
What is Inflection?
Answer: It is class in zend used to modify the string like convert to lowercase, change to url by removing special chars and convert underscore to hyphen.
What is Front Controller?
Answer: 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 Zend_filter?
Zend_filter is used to filter the data as remove the tags, trailing the spaces, remove all except digits.
Can we rename the application folder ?
yes, we can
Can we move the index.php file outside the public folder?
yes, we can
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();?>
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();?>
How do you protect your site from sql injection in zend when using select query?
We 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> );
What is zend framework?
Answer: It is opensource framework created by zend.com (PHP company). It is object oriented and follow the MVC. Zend Framework is focused on building more secure, reliable and fast development.
How to add extra HTML (i.e link) in Zend_Form?
Answer: use Desciption decorator with (escape =false in second parameter).
How can I detect if an optional file has been uploaded?
Answer: Zend_File_Transfer_Adapter_Http's receive() return true.
What is Zend registry?
Answer: It is container for object and values in applications, when you set an object in zend_registry you can access in whole site.
What is Zend_Form?
Answer: It is mainly used to display the form. but along with this we use for filter, validation and formating our form. It have following elements
Element filter
Element validation
Element ordering.
Decorator
Grouping
Sub form
Rendering form elments in single call or one by one for elements.
What is zend helpers?
It can be divided in two parts,
a) Action Helper: the helper is created for controller
b) View Helper: the helper is created for view files (.phtml).
What do you know about zend layout.
Answer: It work as a site template and have following features.
Automatic selection and rendering layout
Provide separate scope for calling element i.e parital, render, partialLoop
What is Inflection?
Answer: It is class in zend used to modify the string like convert to lowercase, change to url by removing special chars and convert underscore to hyphen.
What is Front Controller?
Answer: 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 Zend_filter?
Zend_filter is used to filter the data as remove the tags, trailing the spaces, remove all except digits.
No comments:
Post a Comment