Zend custom controller helper

An action helper is a class that plugs into the controller to provide services to actions. They expand a controller’s functionality without using inheritance and so can be reused across multiple controllers and projects. To add Zend custom controller helper we can add it in library. Here I am creating a custom library for our purpose with the namespace ‘App’, so need to add it in application.ini to autoload these. …

Continue reading

Multiple database in zend framework

Zend framework has two levels of abstraction databases and tables. The database abstraction keeps your PHP code independent from database server you use. It means that it is easier for an application to support multiple database servers. To use multiple database in zend framework we need to zend resource plugin ‘multidb’. You can use it in application.ini file as follows: Now in bootstrap file you need to add database adapters …

Continue reading

Useful tricks for zend framework

I am listing some useful tricks for zend framework here that can be used generally. If you want to change the layout for the particular controller views you should use below code of snippet. You can use it in init() function of controller. To check user authentication you should use it in preDispatch() function of controller, if not logged-in then redirect to login page. It will work for all actions …

Continue reading

Sort multidimensional array

To sort multidimensional array by values, you can use a user-defined comparison function usort. The function sort array by its values using a user-defined comparison function. If you want to sort an array by some non-trivial criteria, you should use this function. For example we have an array to sort: We need to sort this array according to the time in ascending order. So we need to use a user-defined …

Continue reading

Custom view Zend Framework

In zend framework MVC architecture it uses views according to the controller action. But I need to use a custom view for the result of the action like want to get cities options on change of country using ajax. Custom view zend framework without layout. So I came to know this can be done by using $this->renderScript(‘ajax/file_path’) in zend framework. Before this we need to disable the layout of the …

Continue reading

Disable view in zend framework

In an application development we need to use ajax several times. So I decided to use a specific controller for all ajax uses. But I found an application error “‘ajax/gedata.phtml’ not found in” on every action of AjaxController. Then I came to know a solution for this problem. Disable view in zend framework. To disable the layout you need to use To set no render you can use these in …

Continue reading

Get Max id from table in Zend Framework

All aggregate function are like an expression for zend framework. So we need to call them by using an instance of Zend_Db_Expr($expr). To get max id from table in zend framework is an simple example for this as explained below. For example If you want to get max id of the table you need to use new Zend_Db_Expr(‘MAX(id) as id’). $this->getMaxId(); will return a max id of the table. Hope …

Continue reading

Useful Collection Functions of Magento

There are many different useful functions that you can implement in your Collection class. These functions are described in Varien_Data_Collection_Db class. This class file is in lib/Varien/Data/Collection/Db.php Here i am listing some important collection functions that you can use in your collection class: To get Zend_Db_Select instance To get select string of sql object To get the size of collection To get distinct selection To get all data array for …

Continue reading