<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-6572638285277330666</id><updated>2012-01-31T04:08:16.333-08:00</updated><category term='Json'/><category term='Dojo'/><category term='JQuery'/><category term='Joomla'/><category term='Musings'/><category term='Eclipse'/><category term='Php'/><category term='Zend Framewrork'/><category term='Prototype'/><category term='Apache'/><category term='Ruby on Rails'/><category term='Zend Framewrork tutorial'/><category term='SVN'/><title type='text'>Zend Framework</title><subtitle type='html'>All about Zend Framework.</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>42</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-4837457189333121782</id><published>2009-09-17T04:05:00.000-07:00</published><updated>2009-09-17T04:07:25.873-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Php'/><category scheme='http://www.blogger.com/atom/ns#' term='Eclipse'/><category scheme='http://www.blogger.com/atom/ns#' term='SVN'/><title type='text'>Creating project in Eclipse</title><content type='html'>I worked on enterprise level application for one year using Eclipse, Php Designer, and Dreamweaver. We were using Eclipse for checking in and out (updating and committing)&lt;br /&gt; When I joined the team, configuration was already in place in the Eclipse, so I never intend to make configuration. Whenever configuration needed, Team lead was up to the task and was responsible for the entire configuration. I came across new terms like SVN, Commit, and Update for the first time as I was using cute ftp for uploading and downloading files from server before.&lt;br /&gt; Here our job was to write code, complete tasks and commit them using our team lead system. First job in the morning was to update the change as some developers were making change to our project in United States. Our team lead system went of order few times during this period, but we were always looking toward him for the configuration. I remember that once he configured everything on my system, but I never intended to look how everything are done.&lt;br /&gt;Today I found myself stuck in the middle. As I’m going to start working on new project, I tried to do the entire configuration myself.&lt;br /&gt;Believe I was having no clue how to do it. Thanks to some nice soul out there on the internet who have posted the entire step by step procedure. I am going to write those steps for you.&lt;br /&gt;Import project in Eclipse&lt;br /&gt;1. File &gt;&gt; New &gt;&gt; Project &gt;&gt; SVN &gt;&gt; Checkout projects from SVN&lt;br /&gt;2. Next&lt;br /&gt;3. Create a new repository location&lt;br /&gt;4. Next&lt;br /&gt;5. Enter URL as&lt;br /&gt;http://yourserver.com/alpa_proj&lt;br /&gt;6. Next&lt;br /&gt;7. Select the directory&lt;br /&gt;8. Next&lt;br /&gt;9. Choose: checkout as project configured using the New Project Wizard&lt;br /&gt;10. Finish&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-4837457189333121782?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/4837457189333121782/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/09/creating-project-in-eclipse.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/4837457189333121782'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/4837457189333121782'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/09/creating-project-in-eclipse.html' title='Creating project in Eclipse'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-7768804724281757879</id><published>2009-08-26T21:39:00.000-07:00</published><updated>2009-08-26T21:44:30.865-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Php'/><title type='text'>Maxing HTML and PHP code</title><content type='html'>&lt;span style="font-weight:bold;"&gt;Note: This article was written in 2008, when I was working in small firm. Publishing it again here for newbies.&lt;/span&gt;&lt;br /&gt;After working for about one year in website development industry of Pakistan I’ve realized a very serious issue. This may be happening in other countries as well, as I haven’t had worked with international organization, especially professionals.&lt;br /&gt;&lt;br /&gt;The problem is maxing presentational logic with business logic. In simple words I would say maxing HTML with server scripting language like php, asp, coldfusion etc.&lt;br /&gt;Here I would appreciate Microsoft professionals who have done tremendous job by developing Asp.net language. The way they have separated asp.net and html code from C# and VB.NET code is fabulous. However I would like to mention that in the beginning-in early versions of ASP.NET-the problem was there. However with the passage of time and introducing newer and more mature versions like ASP.NET 2.0 they have addressed lots of issues.&lt;br /&gt;Before going into the details of problem mentioned above I would also like to comment about some companies who are providing open source solutions for languages like PHP etc. The contribution made by oscommerce (having the above drawback), zencart(I haven’t studied but heard that it is a bit mature shopping cart solution than oscommerce) and joomla(very nice and more mature content management system) to php cannot be ignored.&lt;br /&gt;The most important contribution is made by those who have developed frameworks(MVC’s) like Zend, Symfony, cakePhp, mojave(lacking documentation and community support) etc. One cannot imagine how worthy and brilliant job they have done and how easier they have made work for lazy professionals like me.&lt;br /&gt;&lt;br /&gt;Two months back I was introduced to mojavi by our company senior web developer. In the first few days I was exhausted and bored. However after developing a simple login application in mojavi I found it quite helpful. But things didn’t move forward coz of lacking documentation and community support.&lt;br /&gt;&lt;br /&gt;I stopped working in mojavi but the virus of working in frameworks sneak in my heart and I started googling different frameworks.&lt;br /&gt;&lt;br /&gt;Next few days I studied cakePhp, symfony and then zend, red their documentation, browse their community support sites and forums and also red articles about their differences.&lt;br /&gt;&lt;br /&gt;Finally and luckily I selected Zend framework-This was because of small configuration overhead of zend framework than other frameworks.&lt;br /&gt;&lt;br /&gt;After working in zend MVC I realized how easier it is to make a web application and how easy it is to extend and maintain existing one.&lt;br /&gt;&lt;br /&gt;Now let me discuss the real problem which has made me sick since last few days.&lt;br /&gt;&lt;br /&gt;After joining new organization 6 days back I was assigned a project for modification. The project was constructed in oscommerce. Boss was expecting that I would finish some small modification in few hours but I trapped in the middle and was unable to browser where modification needs to be made.&lt;br /&gt;&lt;br /&gt;When boss arrived and asked me about the modification I was having no idea what to say and I felt a bit shy at that time. After telling him that I haven’t completed the modification he was a bit shocked and worried because he might be thinking that I was not a right person for the post I had been hired. He took me to his office and asked me about projects I had previously worked on. After showing him my projects he got satisfied but still I could see uncertainty in his eyes.&lt;br /&gt;&lt;br /&gt;Why all this happened and why I trapped in the middle will I think clear the problem I have mentioned in the beginning..&lt;br /&gt;&lt;br /&gt;As I have already mentioned that project was constructed in oscommerce so those how know or have worked in oscommerce will better understand the way oscommerce has been developed. Although they have separated php code form html up to some extent, however it is not as mature as joomla content management system or model view controller frameworks.&lt;br /&gt;&lt;br /&gt;Well, oscommerce was not a big obstacle. The more irritating thing was the way previous programmer had implemented and constructed the pages. After working in office for about 10 hours I managed to complete some modifications but not entire.&lt;br /&gt;&lt;br /&gt;When I came home, installed oscommerce and started doing the same modifications it took me minutes to complete them.&lt;br /&gt;&lt;br /&gt;So I took some deep breathes and started thinking about whom to be blamed. But after thinking for about two hours I realized that no one could be blamed because client needs their projects soon, so developers only think about the construction not about what will happen in future if he himself or someone else try to extend or modify the project.&lt;br /&gt;&lt;br /&gt;Lot of website have been made in similar scenarios and situations.&lt;br /&gt;&lt;br /&gt;So as a professional one needs to be very careful while modifying the project.&lt;br /&gt;&lt;br /&gt;Although professional developed application based on the client recommendations however I think we professional should think seriously about the future extensions and maintenance and try to make application both client and professional friendly.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-7768804724281757879?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/7768804724281757879/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/08/maxing-html-and-php-code.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7768804724281757879'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7768804724281757879'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/08/maxing-html-and-php-code.html' title='Maxing HTML and PHP code'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-4712240840048447804</id><published>2009-08-18T06:05:00.000-07:00</published><updated>2009-08-18T06:10:24.840-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Ruby on Rails'/><title type='text'>Installing Ruby on rails in four easy steps</title><content type='html'>Ruby on rail is used for web application development.&lt;br /&gt;Ruby is object oriented language.&lt;br /&gt;Rail is framework that uses Ruby language to develop robust and scalable web application.&lt;br /&gt;Ruby on rail installation is simple, newbie however find it a bit tricky first.&lt;br /&gt;Here in this article I am going to tell you how can Ruby on rails be installed in windows XP.&lt;br /&gt;&lt;br /&gt;1. Download latest version of Ruby from http://rubyforge.org/projects/rubyinstaller/&lt;br /&gt;2. after the installation double click the exe file. this will start setup wizard which will guide you to the end.&lt;br /&gt;3. once Ruby is installed next step is to set path&lt;br /&gt; =&gt;start =&gt; control panel =&gt; system =&gt;advance =&gt; environment versiables&lt;br /&gt; click path and press edit.&lt;br /&gt; add &lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;;C:\Ruby\bin&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt; at the end of the path, I assumed that you have installed Ruby in drive c.&lt;br /&gt; press oK.&lt;br /&gt;4. now in command prompt&lt;br /&gt;&lt;br /&gt;write&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;gem update --system&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;when the process completed, write&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;gem install rails&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;you have done. now its time to create your first project&lt;br /&gt;&lt;br /&gt;in command prompt, write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;rails firstproject&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Once the projec is create, in command prompt, write&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;cd firstproject&lt;br /&gt;ruby script/server&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;now browse&lt;br /&gt;&lt;br /&gt;http://localhost:3000/&lt;br /&gt;&lt;br /&gt;you will see ruby on rails welcome page.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-4712240840048447804?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/4712240840048447804/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/08/installing-ruby-on-rails-in-four-easy.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/4712240840048447804'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/4712240840048447804'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/08/installing-ruby-on-rails-in-four-easy.html' title='Installing Ruby on rails in four easy steps'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-5100082460093152104</id><published>2009-08-18T00:26:00.000-07:00</published><updated>2009-08-24T04:02:58.179-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Musings'/><title type='text'>Public transport some facts</title><content type='html'>Public transport (also public transportation or public transit or mass transit) comprises passenger transportation service which is used by public [1].&lt;br /&gt;An important role played by public transport in the society is to enable all the member of the society to travel, not only those having driving license and have access to their own automobiles.&lt;br /&gt;Public transport like all other services and facilities in the third word countries is a real dilemma. Elite, which mostly uses their own private automobiles and vehicles, like all other public institutions, organization and facilities, rarely consider improvement in these services. As they never ever use it, so why care about it?&lt;br /&gt;The fact however is, if government gave proper resources and made some improvements, public transit can play a very vital role in generating fair amount of revenue.&lt;br /&gt;Traffic jam which is a real problem in the big cities can be decreased be providing well-designed transport system which is considered more dense then private transport.&lt;br /&gt;I have been using public transport in my beloved country for the last two year, and can say that it has made me mentally sick.&lt;br /&gt;People behave like animals. I am not blaming them for behaving like this, as they are put like animals in buses. They don’t care walking on your feet and pushing with their hands.&lt;br /&gt;Young people specially students stand near entrance, making it hard for the people to get in and out.&lt;br /&gt;Situation become even more deteriorating when a person with his bag selling books, handkerchiefs, toffees, and homeopathic medicines arrived in crowd and start speech explaining benefits of the product he owns.&lt;br /&gt;Beggars also contribute to the noisy environment, trying hard to collect money for no work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-5100082460093152104?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/5100082460093152104/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/08/public-transport-some-facts.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/5100082460093152104'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/5100082460093152104'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/08/public-transport-some-facts.html' title='Public transport some facts'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-3596805764895768488</id><published>2009-08-11T23:04:00.000-07:00</published><updated>2009-08-11T23:13:52.083-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Dojo'/><title type='text'>Dojo: Creating image using dojo script</title><content type='html'>Dojo provides numerous functionality like:&lt;br /&gt;1.Easy and smooth creation of different widget such as dojo grid, forms, datapicker, calendar etc.&lt;br /&gt;2.Prolific method of interacting with html elements.&lt;br /&gt;3.Achievement of ajax functionality with far more less code.&lt;br /&gt;In this article I am going to discuss how to create an image element using dojo script and attach that image to certain html element.&lt;br /&gt;In order to achieve functionality on loading the page, you will need to use dojo.addOnLoad() method. This takes the following form.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br /&gt;    dojo.addOnLoad(function(){&lt;br /&gt;        alert(&amp;#8216;called on load of page&amp;#8217;);&lt;br /&gt;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now in the next few lines we are going to put the actual functionality.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br /&gt;    dojo.addOnLoad(function(){&lt;br /&gt;        dojo.extend(dojo.NodeList, {&lt;br /&gt;            addImage: function() {&lt;br /&gt;            &lt;br /&gt;            return this;&lt;br /&gt;        }&lt;br /&gt;    });&lt;br /&gt;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The most important things here are extending dojo.NodeList and then adding addImage function that initially has nothing, but we are going to add real functionality to it later on. This addImage method will contain the functionality for creating an image.&lt;br /&gt;The question here however is, why we extend NodeList.&lt;br /&gt;Well this is pretty simple. If you want to achieve functionality like;&lt;br /&gt;dojo.query(‘input[id=name]’).addImage().removeClass(‘complusory_image’);&lt;br /&gt;you will need to extend you method from NodeList. Doing so will enable you to access entire NodeList method in the way above.&lt;br /&gt;&lt;br /&gt;Don’t worry about dojo.query() method, I will explain it shortly for you.&lt;br /&gt;Now lets put the real script for creating img tag in our addImage method.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;var img = dojo.doc.createElement('img');&lt;br /&gt;dojo.attr(img, {&lt;br /&gt;    src: &amp;quot;path/to/imges/img.png&amp;quot;,&lt;br /&gt;    alt: &amp;quot;This is my simple image&amp;quot;,&lt;br /&gt;    style: {cursor: &amp;quot;pointer&amp;quot;}&lt;br /&gt;});&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the first line we have created img tag. In the second line we have attached different attributes to the img. You can define as many valid attributes associated with img tag as you wish.&lt;br /&gt;&lt;br /&gt;The code in the addImage function looks, however, a bit different. See the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br /&gt;dojo.addOnLoad(function(){&lt;br /&gt;    dojo.extend(NodeList, {&lt;br /&gt;            addImage: function(args){&lt;br /&gt;                this.forEach(function(n){&lt;br /&gt;                    var img = dojo.doc.createElement('img');&lt;br /&gt;                    dojo.attr(img, {&lt;br /&gt;                        src: &amp;quot;path/to/imges/img.png&amp;quot;,&lt;br /&gt;                        alt: &amp;quot;This is my simple image&amp;quot;,&lt;br /&gt;                        style: {cursor: &amp;quot;pointer&amp;quot;}&lt;br /&gt;                    });&lt;br /&gt;                    dojo.place(img, n, &amp;quot;after&amp;quot;);&lt;br /&gt;                });&lt;br /&gt;            return this;&lt;br /&gt;        }&lt;br /&gt;    });&lt;br /&gt;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The function for addImage contain args as parameter. This means that the image tag created can be attached to as many html elements as you like. In the forEach loop we create image tag and attach at to the arguments passed to it.&lt;br /&gt;Now in the dojo.addOnLoad function, at the end, write the following script.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;dojo.query(&amp;#8216;input[id=name]&amp;#8217;).addImage();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The above script states that attach an image to input tag having id equals to name.&lt;br /&gt;It you want to attach element to all input tags on your page, write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;dojo.query(&amp;#8216;input&amp;#8217;).addImage(); &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The final script on my page look like this.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br /&gt;dojo.addOnLoad(function(){&lt;br /&gt;    dojo.extend(NodeList, {&lt;br /&gt;            addImage: function(args){&lt;br /&gt;                this.forEach(function(n){&lt;br /&gt;                    var img = dojo.doc.createElement('img');&lt;br /&gt;                    dojo.attr(img, {&lt;br /&gt;                        src: &amp;quot;path/to/imges/img.png&amp;quot;,&lt;br /&gt;                        alt: &amp;quot;This is my simple image&amp;quot;,&lt;br /&gt;                        style: {cursor: &amp;quot;pointer&amp;quot;}&lt;br /&gt;                    });&lt;br /&gt;                    dojo.place(img, n, &amp;quot;after&amp;quot;);&lt;br /&gt;                });&lt;br /&gt;            return this;&lt;br /&gt;        }&lt;br /&gt;    });&lt;br /&gt;    dojo.query(&amp;quot;input[id=name]&amp;quot;).addImage();&lt;br /&gt;});&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-3596805764895768488?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/3596805764895768488/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/08/dojo-creating-image-using-dojo-script.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/3596805764895768488'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/3596805764895768488'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/08/dojo-creating-image-using-dojo-script.html' title='Dojo: Creating image using dojo script'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-72190721422160434</id><published>2009-07-31T03:26:00.000-07:00</published><updated>2009-08-26T00:55:36.889-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Dojo'/><title type='text'>Creating dojo datepicker with dojo script</title><content type='html'>&lt;p&gt;Dojo date picker is nice and beautiful widget. The nice thing about any dojo widgets is that they can be easily attached to appropriate html tag. To assign date picker to input box take the following cod.&lt;/p&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed #999999; padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: #000000; background-color: #eeeeee; font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;script src=&amp;rdquo;path/to/dojo.js&amp;rdquo;&amp;gt;&lt;br /&gt;require(&amp;lsquo;dijit.form.DateTextBox&amp;rsquo;);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;style type=text/css&amp;gt;&lt;br /&gt;    @import &amp;quot;path/to/dojo/dijit/themes/tundra/tundra.css&amp;quot;;&lt;br /&gt;&amp;lt;/style&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&amp;lt;body class= &amp;ldquo;tundra&amp;rdquo;&amp;gt;&lt;br /&gt;    &amp;lt;input type=&amp;rdquo;text&amp;rdquo; dojoType=&amp;rdquo;dijit.form.DateTextBox&amp;rdquo; name=&amp;rdquo;dd&amp;rdquo; id=&amp;rdquo;dd&amp;rdquo;/&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;If you correctly include dojo.js and tundra.css, you will see a nice&lt;/p&gt;&lt;p&gt;&lt;a href="http://blogs.fanbox.com/ZendFramework"&gt;Read More&lt;/a&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-72190721422160434?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/72190721422160434/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-dojo-datepicker-with-dojo.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/72190721422160434'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/72190721422160434'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-dojo-datepicker-with-dojo.html' title='Creating dojo datepicker with dojo script'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-2623128366216703206</id><published>2009-07-27T05:40:00.000-07:00</published><updated>2009-07-29T22:13:17.945-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><category scheme='http://www.blogger.com/atom/ns#' term='Json'/><category scheme='http://www.blogger.com/atom/ns#' term='Dojo'/><title type='text'>Zend Framework, dojo and Json</title><content type='html'>I have already written about json in one, actually some of my articles. Cool functionality can be achieved using json. Thanks to http://www.json.org, http://www.zend.com and http://www.dojotoolkit.org for provide easier solutions.&lt;br /&gt;&lt;br /&gt;I'm not gonna talk what these three are all about, but instead share a little secret about these.&lt;br /&gt;Json creation in dojo is as simple as this.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;var arr = new Array();&lt;br /&gt;arr[0] = &amp;#8220;apple&amp;#8221;;&lt;br /&gt;arr[1] = &amp;#8220;ball&amp;#8221;;&lt;br /&gt;arr[2] = &amp;#8220;cat&amp;#8221;;&lt;br /&gt;&lt;br /&gt;dojo.toJson(arr);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Using Zend to convert array into json took only one line of code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Json::encode($arr);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;And decoding- converting json to array, is as simple as this&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Json::decode(json_string);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-2623128366216703206?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/2623128366216703206/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-dojo-and-json.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/2623128366216703206'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/2623128366216703206'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-dojo-and-json.html' title='Zend Framework, dojo and Json'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-7286303110325432609</id><published>2009-07-14T01:32:00.000-07:00</published><updated>2009-07-14T01:35:01.554-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Apache'/><title type='text'>Apache: Setting virtual host on localhost</title><content type='html'>It was up to this task since yesterday. I haven’t done this before, setting sub domain- virtual host on local system. I tried a lot yesterday but in vain, however when I came to office today I configured it successfully.&lt;br /&gt;As I was stuck in the middle and feel lot of pain, so I better write it for those facing the same issue.&lt;br /&gt;Why I was up to this task?&lt;br /&gt;Well, actually my client was facing problem and reported that session is not working properly on domain and sub domain. So I was having no way other than setting virtual host.&lt;br /&gt;However before leaving yesterday, I talked to my client that I am unable to solve this problem. He told me that I shouldn’t be worried about it because he will take care of this issue. The more important thing is that when I arrived today, I found that the problem has already been solved. Thanks to him for giving my favor.&lt;br /&gt;Thought the problem has been solved, but still is worthy to write a small post here because I have successfully solved the problem.&lt;br /&gt;Before going to discuss it, I would like to tell you that the configuration has been taken place on window so the paths may not be same.&lt;br /&gt;Let have a look.&lt;br /&gt;First of all you will need to open.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;C:\xampp\apache\conf\extra\httpd-vhosts.conf&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;I assumed that you have install xampp.&lt;br /&gt;And add following lines to httpd-vhosts.conf file.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;NameVirtualHost *:80&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;    ServerName localhost&lt;br /&gt;    DocumentRoot &amp;quot;C:/xampp/htdocs/&amp;quot;&lt;br /&gt;    ServerAdmin admin@localhost&lt;br /&gt;&amp;lt;/VirtualHost&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;VirtualHost *:80&amp;gt;&lt;br /&gt;    ServerName mysite.com.localhost&lt;br /&gt;    DocumentRoot &amp;quot;C:/xampp/htdocs/mysite/&amp;quot;&lt;br /&gt;    ServerAdmin admin@mysite.com.localhost&lt;br /&gt;&amp;lt;Directory &amp;quot;C:/xampp/htdocs/mysite/&amp;quot;&amp;gt;&lt;br /&gt;    Options Indexes FollowSymLinks&lt;br /&gt;    AllowOverride FileInfo&lt;br /&gt;    Order allow,deny&lt;br /&gt;    Allow from all&lt;br /&gt;&amp;lt;/Directory&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here I have defined server localhost pointing to my default htdocs directory and another host mysite.com.localhost pointing to "C:/xampp/htdocs/mysite/".&lt;br /&gt;Another important thing is &lt;VirtualHost *:80&gt;&lt;br /&gt;Here you would need to specify the port. In  my case its 80.&lt;br /&gt;If you don’t specify the port on which apache listen, apache may take you to the same page for both the server. So be careful.&lt;br /&gt;&lt;br /&gt;Next go to your Window/system32/dirvers/etc/ and open hosts file.&lt;br /&gt;You will find&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;127.0.0.1       localhost&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;At the end of the file. Add following line next to it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;127.0.0.1    mysite.com.localhost&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Reboot your system and you are done.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-7286303110325432609?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/7286303110325432609/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/apache-setting-virtual-host-on.html#comment-form' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7286303110325432609'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7286303110325432609'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/apache-setting-virtual-host-on.html' title='Apache: Setting virtual host on localhost'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-2606098565536949663</id><published>2009-07-14T01:23:00.000-07:00</published><updated>2009-07-14T01:29:02.498-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Php'/><title type='text'>Method chaining in object oriented programming</title><content type='html'>In my previous article I discussed some of the nice thing of object oriented programming. Inheritance –creating sub classes from inheriting parent, contain all the attributes of the parent class plus its own. Polymorphism means different form, like overloading and overriding methods and dynamic binding- deciding which class in the inheritance tree should be called on runtime, are techniques that give great benefits to programmers.&lt;br /&gt;In this article I am going to show you a simple but very useful trick while using “this” keyword for method chaining. “this” when use in the class, refer to the same class.&lt;br /&gt;Consider the following example.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class Person {&lt;br /&gt;    protected $_name;&lt;br /&gt;    protected $_age;&lt;br /&gt;    protected $_gender;&lt;br /&gt;    &lt;br /&gt;    public function setName($name) {&lt;br /&gt;        $this-&amp;gt;_name  = $name;&lt;br /&gt;    }&lt;br /&gt;    public function getName() {&lt;br /&gt;        return $this-&amp;gt;_name; &lt;br /&gt;    }&lt;br /&gt;    public function setAge ($age) {&lt;br /&gt;        $this-&amp;gt;_name  = $age;&lt;br /&gt;    }&lt;br /&gt;    public function getAge() {&lt;br /&gt;        return $this-&amp;gt;_age; &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public function setGender($gender) {&lt;br /&gt;        $this-&amp;gt;_gender  = $gender;&lt;br /&gt;    }&lt;br /&gt;    public function getGender() {&lt;br /&gt;        return $this-&amp;gt;_gender; &lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In object oriented programming it’s always a good practice to define getter and setters. In php you can define __set and __get as setters and getter.&lt;br /&gt;&lt;br /&gt;To create an object of the above class and define person properties, we will need to write the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$person = new Person();&lt;br /&gt;$person-&amp;gt;setName(&amp;#8220;person_name&amp;#8221;);&lt;br /&gt;$person-&amp;gt;setAge(24);&lt;br /&gt;$person-&amp;gt;setGender(&amp;#8220;male&amp;#8221;);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;And now If you want to get these values, write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$person-&amp;gt;getName();&lt;br /&gt;$person-&amp;gt;getAge();&lt;br /&gt;$person-&amp;gt;getGender();&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Well, if you want to set values using a single statement, you will need a code similar to this.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;setName(&amp;#8216;person_name&amp;#8217;)-&amp;gt;setAge(24)-&amp;gt;setGender(&amp;#8220;male&amp;#8221;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;To achieve this, you will need to write the following statement in all your setters.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public function setName($name) {&lt;br /&gt;    $this-&amp;gt;_name  = $name;&lt;br /&gt;    return $this;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The only thing we need here is “return $this”. This statement return a reference to the same object.&lt;br /&gt;Place this statement in your setAge() and setGender(), and now you can write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;setName(&amp;#8216;person_name&amp;#8217;)-&amp;gt;setAge(24)-&amp;gt;setGender(&amp;#8220;male&amp;#8221;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;for setting all the three properties.&lt;br /&gt;Any suggestion is welcome. Cheers&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-2606098565536949663?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/2606098565536949663/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/method-chaining-in-object-oriented.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/2606098565536949663'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/2606098565536949663'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/method-chaining-in-object-oriented.html' title='Method chaining in object oriented programming'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-3890030836557366028</id><published>2009-07-14T01:20:00.000-07:00</published><updated>2009-07-14T01:21:53.926-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Php'/><title type='text'>PHP: Object Oriented Programming</title><content type='html'>Object oriented programming concepts were introduced in PHP1.4, I guess.&lt;br /&gt;How many people around you play with object oriented programming?&lt;br /&gt;If not working in any kind of MVC frameworks, I guess very short number of people.&lt;br /&gt;Developers are often used to structured programming and don’t bother themselves learning object oriented programming concepts and paradigm.&lt;br /&gt;Well, when software engineers realized that it’d become very difficult to manage and maintain thousand lines of code as well as impossible to represent real world object in computer world, object oriented programming was introduced. Since then dramatic improvements have been made to OOP.&lt;br /&gt;&lt;br /&gt;In object oriented programming inheritance, polymorphism, encapsulation, dynamic binding and exception handling has great value, usage and advantages, however class and objects are the most basic concept.&lt;br /&gt;&lt;br /&gt;Class is blue print containing properties and method associated with same entity. Object is the instance of the class and is used to access properties and method of the class.&lt;br /&gt;In addition to OOP, design pattern make jobs easier for the programmers.&lt;br /&gt;Singleton, factory and specially MVC design patterns are very useful these days.&lt;br /&gt;&lt;br /&gt;In singleton design pattern one object of the class exist throughout the life cycle of the software application. If programmer tries to instantiate another object of the same class, a reference to the object instantiated earlier, is granted.&lt;br /&gt;&lt;br /&gt;A class implementing factory design pattern works as bridge between multiple classes. Consider an example of using multiple database servers like SQL Server and Oracle. If you are developing an application using SQL Server database as backend, but in future need to change backend database to oracle, you will need to modify all your code, if you haven’t written your code following factory design pattern.&lt;br /&gt;In factory design pattern you need to do very little work to achieve this. A class implementing factory design pattern takes care for you and lessen your burden. Switching from database server won’t bother you at all. You just need to make some small changes in your configuration file.&lt;br /&gt;&lt;br /&gt;Revolution of MVC design patterns cause dramatic changes in software development life cycle. Prior to MVC, developers were mixing code all around. It was difficult to figure out where the business code resides and where presentation code is written. Intelligent software engineers, though, were trying hard to separate their business logic from presentation logic; this however wasn’t effective enough for new comers to understand their code and to do necessary maintenance. Without the help of the person behind the project, it’d taken more time to understand the directory structure used.&lt;br /&gt;These draw backs were mostly addressed when MVC design patterns were introduced.&lt;br /&gt;&lt;br /&gt;In MVC design pattern M stands for Model. Model contains your application’s business logic.&lt;br /&gt;V stands for View. It’s the presentation layer.&lt;br /&gt;While C stands for controller that work as glue between view and model. From glue I mean it takes data from view and give it to the model, model then process the data and produced desired results. The data, thus obtained, is given to the view. Controller can also be compared to event handlers. It responds to certain events such as posting the data back to server by clicking submitted data.&lt;br /&gt;Hopefully I will unveil some other fact about OOP and design pattern later some time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-3890030836557366028?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/3890030836557366028/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/php-object-oriented-programming.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/3890030836557366028'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/3890030836557366028'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/php-object-oriented-programming.html' title='PHP: Object Oriented Programming'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-4757185665667790674</id><published>2009-07-13T10:20:00.000-07:00</published><updated>2009-07-13T10:26:01.190-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><category scheme='http://www.blogger.com/atom/ns#' term='Dojo'/><title type='text'>Create dojo tab cotainer in Zend Framework</title><content type='html'>&lt;span style="font-size:130%;"&gt;Try online: &lt;a href="http://faheem.asim.pk/container/tab"&gt;Tab Container&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;In my previous posts I discussed how to create accordion container holding accordion panes and border container having content panes.&lt;br /&gt;In this article I am going to show you how easy it is to create tab continer that hold contents panes. Each content pane having different contents. Contents in one tab pane are shown at a time. when use click on the tab pane's title, contents in that tab pane are shown.&lt;br /&gt;Before reading this post, you better read and implement what I have discussed in my article "&lt;a href="http://zendgeek.blogspot.com/2009/06/zend-framework-and-dojo-configuration.html"&gt;Zend Framework and Dojo: configuration&lt;/a&gt;". Before creating tab continer and panes, you will need to understand and perform necessary configuration.I assume that you have read the post I  have mentioned and have done the necessary configuration. Now let's get started.&lt;br /&gt;First of all, you will need to create your controller as &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class ContainerController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt; public function tabAction()&lt;br /&gt; {&lt;br /&gt;  &lt;br /&gt; }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;In the code above we have defined our ContainerController extending it from Zend_Controller_Action, and then we have defined our tabAction.&lt;br /&gt;Now, the next step is to create tab.phtml in /application/views/scripts/container/ and place the following code in it.&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$this-&amp;gt;tabContainer()-&amp;gt;captureStart('main-container',&lt;br /&gt;                                    array('design' =&amp;gt; 'headline'),&lt;br /&gt;                                    array(&lt;br /&gt;                                            'style'=&amp;gt;'height:400px;width:800px'&lt;br /&gt;                                     ));&lt;br /&gt;&lt;br /&gt;echo $this-&amp;gt;contentPane(&lt;br /&gt; 'home',&lt;br /&gt; 'This is home page',&lt;br /&gt; array('region' =&amp;gt; 'top','title'=&amp;gt;'Home'),&lt;br /&gt; array('style' =&amp;gt; 'background-color: white;')&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;echo  $this-&amp;gt;contentPane(&lt;br /&gt; 'gallery',&lt;br /&gt; 'Contents of gallery here',&lt;br /&gt; array('region' =&amp;gt; 'left', 'title'=&amp;gt;'Gallery'),&lt;br /&gt; array('style' =&amp;gt; 'width: 200px; background-color: white;')&lt;br /&gt;);&lt;br /&gt;                             &lt;br /&gt;echo $this-&amp;gt;contentPane(&lt;br /&gt; 'Blog',&lt;br /&gt; 'Blog post here',&lt;br /&gt; array('region' =&amp;gt; 'center','title'=&amp;gt;'Blog'),&lt;br /&gt; array('style' =&amp;gt; 'background-color: white;')&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;echo $this-&amp;gt;contentPane(&lt;br /&gt; 'about',&lt;br /&gt; 'Information about your company etc',&lt;br /&gt; array('region' =&amp;gt; 'bottom', 'title'=&amp;gt;'About Us'),&lt;br /&gt; array('style' =&amp;gt; 'background-color: white;')&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;echo $this-&amp;gt;tabContainer()-&amp;gt;captureEnd('main-container');&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here we first call captureStart() method of tabContainer() dojo view helper, giving it an id, and array containing tab container special attributes. Next we define content panes. Each content pane holds the data. The contents panes in the tab container will become tab panes.&lt;br /&gt;each content pane is defined as&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;echo $this-&amp;gt;contentPane(&lt;br /&gt; 'home',&lt;br /&gt; 'This is home page',&lt;br /&gt; array('region' =&amp;gt; 'top','title'=&amp;gt;'Home'),&lt;br /&gt; array('style' =&amp;gt; 'background-color: white;')&lt;br /&gt;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here "home" is the id of the content page, Next "string" is the contents that will appear in the tab pane. Next we have defined the array of the special attributes of the contents. Here title is the most important attribute. This title will appear on the tab. The last array contain css related attributes.&lt;br /&gt;That's it. we have now written all necessary code for creating nice and beautiful Tab container.&lt;br /&gt;Cheers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-4757185665667790674?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/4757185665667790674/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/create-dojo-tab-cotainer-in-zend.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/4757185665667790674'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/4757185665667790674'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/create-dojo-tab-cotainer-in-zend.html' title='Create dojo tab cotainer in Zend Framework'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-804934249454641204</id><published>2009-07-12T22:35:00.000-07:00</published><updated>2009-07-12T23:04:38.983-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Framework  SQL Joins Examples</title><content type='html'>You may have custom of using advanced queries. It often requires writing complex queries if you are working on enterprise, large scale web application(s).&lt;br /&gt; The use of joins can never be ignored.&lt;br /&gt;Zend Framework developers have done tremendous  job by providing simple method for implementing joins.&lt;br /&gt;Lets look some examples of different type of joins.&lt;br /&gt;Before discussing joins lets consider we have two tables, “authors” and “books”.&lt;br /&gt;These are associated with author_id.&lt;br /&gt;&lt;br /&gt;1. Inner Join&lt;br /&gt;The simplest query will be&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$select = $this-&amp;gt;_db-&amp;gt;select()&lt;br /&gt;                -&amp;gt;from('books',array('col1','col2'&amp;#8230;..))&lt;br /&gt;                -&amp;gt;joinInner('authors','books.id=authors.bks_id',array('col1','col3'&amp;#8230;))&lt;br /&gt;                -&amp;gt;where('where condition here')&lt;br /&gt;                -&amp;gt;order('column name ASC/DESC');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;2. Left Join&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$select = $this-&amp;gt;_db-&amp;gt;select()&lt;br /&gt;                -&amp;gt;from('books',array('col1','col2'&amp;#8230;..))&lt;br /&gt;                -&amp;gt;joinLeft('authors','books.id=authors.bks_id',array('col1','col3'&amp;#8230;))&lt;br /&gt;                -&amp;gt;where('where condition here')&lt;br /&gt;                -&amp;gt;group('group by column name here')&lt;br /&gt;                -&amp;gt;order('column name ASC/DESC');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;3. Right Join&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$select = $this-&amp;gt;_db-&amp;gt;select()&lt;br /&gt;                -&amp;gt;from('books',array('col1','col2'&amp;#8230;..))&lt;br /&gt;                -&amp;gt;joinRight('authors','books.id=authors.bks_id',array('col1','col3'&amp;#8230;))&lt;br /&gt;                -&amp;gt;where('where condition here')&lt;br /&gt;                -&amp;gt;group('group by column name here')&lt;br /&gt;                -&amp;gt;order('column name ASC/DESC');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;4. Full Join&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$select = $this-&amp;gt;_db-&amp;gt;select()&lt;br /&gt;                -&amp;gt;from('books',array('col1','col2'&amp;#8230;..))&lt;br /&gt;                -&amp;gt;joinFull('authors','books.id=authors.bks_id',array('col1','col3'&amp;#8230;))&lt;br /&gt;                -&amp;gt;where('where condition here')&lt;br /&gt;                -&amp;gt;group('group by column name here')&lt;br /&gt;                -&amp;gt;order('column name ASC/DESC');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;5. Cross Join &lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$select = $this-&amp;gt;_db-&amp;gt;select()&lt;br /&gt;                -&amp;gt;from('books',array('col1','col2'&amp;#8230;..))&lt;br /&gt;                -&amp;gt;joinFull('authors','books.id=authors.bks_id',array('col1','col3'&amp;#8230;))&lt;br /&gt;                -&amp;gt;where('where condition here')&lt;br /&gt;                -&amp;gt;group('group by column name here')&lt;br /&gt;                -&amp;gt;order('column name ASC/DESC');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Once you write these queries, you can fetch a single row or multiple rows as&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$result = $this-&amp;gt;getAdapter()-&amp;gt;fetchRow($select);&lt;br /&gt;$result = $this-&amp;gt;getAdapter()-&amp;gt;fetchAll($select);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The first statement fetch only one row, while the second statement fetch the entire dataset.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-804934249454641204?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/804934249454641204/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-sql-joins-examples.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/804934249454641204'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/804934249454641204'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-sql-joins-examples.html' title='Zend Framework  SQL Joins Examples'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-8653705083431137254</id><published>2009-07-12T22:26:00.000-07:00</published><updated>2009-07-12T22:33:12.289-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Php'/><category scheme='http://www.blogger.com/atom/ns#' term='Json'/><category scheme='http://www.blogger.com/atom/ns#' term='Prototype'/><title type='text'>Creating Json response in php, a nice example</title><content type='html'>While working with AJAX, you will need to get data after sending request to the server. You can use three ways to get the data form the server.&lt;br /&gt;1. In xml Format&lt;br /&gt;2. HTML Format&lt;br /&gt;3. Json Format&lt;br /&gt;Though xml has several advantages, however processing data at the client will put extra burden.&lt;br /&gt;HTML, can easily be handle, is however more resource or you can say bandwidth extensive.&lt;br /&gt;So JSON fall in the middle of both.&lt;br /&gt;PHP provide a very easy way to create JSON response. Once you get data at client side you will need much later code to process response than xml document.&lt;br /&gt;Let’s first look at the server side.&lt;br /&gt;For example we have the following array.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$data = array(&lt;br /&gt;            'items'=&amp;gt;array(&lt;br /&gt;                        'firstname'=&amp;gt;'faheem',&lt;br /&gt;                        'lastname'=&amp;gt;'abbas',&lt;br /&gt;                        'address'=&amp;gt;'pakistan'&lt;br /&gt;                        )&lt;br /&gt;            );&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;To create JSON response, simply write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;echo json_encode($data); &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This will give the following result&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;{&amp;quot;items&amp;quot;:{&amp;quot;firstname&amp;quot;:&amp;quot;faheem&amp;quot;,&amp;quot;lastname&amp;quot;:&amp;quot;abbas&amp;quot;,&amp;quot;address&amp;quot;:&amp;quot;pakistan&amp;quot;}}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now at the client side to send AJAX request, you will need to create the following code.&lt;br /&gt;Keep in mind that we are using prototype for making AJAX request.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br /&gt;function getData()&lt;br /&gt;{&lt;br /&gt;    new Ajax.Request(&lt;br /&gt;&lt;br /&gt;        &amp;#8220;http://localhost/getdata.php&amp;quot;, /* this is url of the php file that create JSON response.*/&lt;br /&gt;            {&lt;br /&gt;                method:'post',&lt;br /&gt;                onSuccess: processData&lt;br /&gt;        }&lt;br /&gt;    );&lt;br /&gt;}&lt;br /&gt;function processData(rsp)&lt;br /&gt;{&lt;br /&gt;var response = eval('(' + rsp.responseText + ')');&lt;br /&gt;var firstname = response.items(0).firstname;&lt;br /&gt;var lastname = response.items(0).lastname;&lt;br /&gt;var address  = response.items(0).address;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;That's it.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-8653705083431137254?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/8653705083431137254/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-json-response-in-php-nice.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8653705083431137254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8653705083431137254'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-json-response-in-php-nice.html' title='Creating Json response in php, a nice example'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-4365917402026829284</id><published>2009-07-12T11:26:00.000-07:00</published><updated>2009-07-13T10:27:31.250-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><category scheme='http://www.blogger.com/atom/ns#' term='Dojo'/><title type='text'>Creating dojo border container in Zend Framework</title><content type='html'>&lt;span style="font-size:130%;"&gt;Try Online : &lt;a href="http://faheem.asim.pk/container/border"&gt;Border Container&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;In my previous artilce I discuss how to create accordion container and panes. If you wish to create accordion container and panes, read my article "Creating dojo accordion Container in Zend".&lt;br /&gt;If you don't know how to configure dojo and Zend Framework, read &lt;a href="http://zendgeek.blogspot.com/2009/06/zend-framework-and-dojo-configuration.html"&gt;here&lt;/a&gt;.&lt;br /&gt;In this article, however I am going to discuss how to create border container. Border continer divide our page in different section so that we can display different contents in those sectitons.&lt;br /&gt;&lt;br /&gt;To create the border container we first need to create our controller as &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class ContainerController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;public function borderAction()&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now in your /application/views/scripts/container/border.phtml, place the following code.&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$this-&amp;gt;borderContainer()-&amp;gt;captureStart('main-container',&lt;br /&gt;                                   array('design' =&amp;gt; 'headline'),&lt;br /&gt;                                   array(&lt;br /&gt;                                           'style'=&amp;gt;'height:400px;width:800px',&lt;br /&gt;                                        'align' =&amp;gt; 'center'&lt;br /&gt;                                    ));&lt;br /&gt;&lt;br /&gt;echo $this-&amp;gt;contentPane(&lt;br /&gt;'menuPane',&lt;br /&gt;'This is the menu pane',&lt;br /&gt;array('region' =&amp;gt; 'top'),&lt;br /&gt;array('style' =&amp;gt; 'background-color: darkblue;color:white')&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;echo  $this-&amp;gt;contentPane(&lt;br /&gt;'navPane',&lt;br /&gt;'This is the navigation pane',&lt;br /&gt;array('region' =&amp;gt; 'left'),&lt;br /&gt;array('style' =&amp;gt; 'width: 200px; background-color: lightblue;')&lt;br /&gt;);&lt;br /&gt;                           &lt;br /&gt;echo $this-&amp;gt;contentPane(&lt;br /&gt;'mainPane',&lt;br /&gt;'This is the main content pane area',&lt;br /&gt;array('region' =&amp;gt; 'center'),&lt;br /&gt;array('style' =&amp;gt; 'background-color: white;')&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;echo $this-&amp;gt;contentPane(&lt;br /&gt;'statusPane',&lt;br /&gt;'Status area',&lt;br /&gt;array('region' =&amp;gt; 'bottom'),&lt;br /&gt;array('style' =&amp;gt; 'background-color: lightgray;')&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;echo $this-&amp;gt;borderContainer()-&amp;gt;captureEnd('main-container');&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Here we have called captureStart() method to start our border container, and then we have placed different content panes.&lt;br /&gt;Each content pane has an "id", "contents" it holds, array containing content panes attributes, and an array containing css attributes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-4365917402026829284?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/4365917402026829284/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-dojo-border-container-in-zend.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/4365917402026829284'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/4365917402026829284'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-dojo-border-container-in-zend.html' title='Creating dojo border container in Zend Framework'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-9010809995809030262</id><published>2009-07-12T11:25:00.000-07:00</published><updated>2009-07-13T10:28:07.249-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><category scheme='http://www.blogger.com/atom/ns#' term='Dojo'/><title type='text'>Creating dojo accordion Container/panes in Zend</title><content type='html'>&lt;span style="font-size:130%;"&gt;Try Online : &lt;a href="http://faheem.asim.pk/container/accordion"&gt;Accordion Container&lt;/a&gt;&lt;/span&gt;&lt;br /&gt;Dojo provide very easy and nice way of creating different containers such as accordion, tab, border, and stack  etc.&lt;br /&gt; These containers hold different type of panes. These different panes in turn use to hold contents. contents can be simple text or it can be complete html.&lt;br /&gt; Zend Framework collaboration with Dojo has made things quite easy. Zend Framework provide view helpers to achieve different type of dojo functionality.&lt;br /&gt; In this article I am going to discuss how to create Accordion Container. accordion Container hold accordion panes. Each accordion pane hold different contents and open in a stylish way when user click on the title of the pane.&lt;br /&gt; In order to enable dojo helpers in you Zend Framework application, you will need to make some initial configuration. read my tutorial "&lt;a href="http://zendgeek.blogspot.com/2009/06/zend-framework-and-dojo-configuration.html"&gt;Zend Framework and Dojo: configuration&lt;/a&gt;" before reading this tutorial. After successfull configuration create a controller called "ContinerController.php" in your controllers directory and place the following code in it. &lt;p&gt;&lt;/p&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class ContainerController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;   public function accordionAction()&lt;br /&gt;   {&lt;br /&gt;      &lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We have only defined an action in our controller, putting no code at all. you however can put whatever code you wish.&lt;br /&gt;Now in /application/views/scripts/container/accordion.phtml place the following code.&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;$this-&amp;gt;accordionContainer()-&amp;gt;captureStart('main-container',&lt;br /&gt;                                      array('design' =&amp;gt; 'headline'),&lt;br /&gt;                                      array(&lt;br /&gt;                                              'style'=&amp;gt;'height:400px;width:400px'&lt;br /&gt;                                       ));&lt;br /&gt;&lt;br /&gt;echo $this-&amp;gt;accordionPane(&lt;br /&gt;     'home',&lt;br /&gt;   'This is home page',&lt;br /&gt;   array('region' =&amp;gt; 'top','title'=&amp;gt;'Home'),&lt;br /&gt;   array('style' =&amp;gt; 'background-color: white;')&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;echo  $this-&amp;gt;accordionPane(&lt;br /&gt;   'gallery',&lt;br /&gt;   'Contents of gallery here',&lt;br /&gt;   array('region' =&amp;gt; 'left', 'title'=&amp;gt;'Gallery'),&lt;br /&gt;   array('style' =&amp;gt; 'background-color: white;')&lt;br /&gt;);&lt;br /&gt;                                 &lt;br /&gt;echo $this-&amp;gt;accordionPane(&lt;br /&gt;   'Blog',&lt;br /&gt;   'Blog post here',&lt;br /&gt;   array('region' =&amp;gt; 'center','title'=&amp;gt;'Blog'),&lt;br /&gt;   array('style' =&amp;gt; 'background-color: white;')&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;echo $this-&amp;gt;accordionContainer()-&amp;gt;captureEnd('main-container');&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The code is pretty simple. we first call captureStart() method on accordionContainer(). this will start accordion container for us.&lt;br /&gt;Once the accordion continer is started, we need to put accordion panes in it and at the end we will need to call captureEnd() method to end our accordion container.&lt;br /&gt;The container holding the following accordion pane.&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;echo $this-&amp;gt;accordionPane(&lt;br /&gt;     'home',&lt;br /&gt;   'This is home page',&lt;br /&gt;   array('region' =&amp;gt; 'top','title'=&amp;gt;'Home'),&lt;br /&gt;   array('style' =&amp;gt; 'background-color: white;')&lt;br /&gt;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The above code call accordionPane() helper method. This dojo helper method take an "id", "contents" to be displayed in the accordion pane, an array containing the special attributes of the accordion pane, and array of css attributes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-9010809995809030262?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/9010809995809030262/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-dojo-accordion-containerpanes.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/9010809995809030262'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/9010809995809030262'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-dojo-accordion-containerpanes.html' title='Creating dojo accordion Container/panes in Zend'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-7602979437216063915</id><published>2009-07-12T11:23:00.000-07:00</published><updated>2009-07-12T11:25:19.209-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><category scheme='http://www.blogger.com/atom/ns#' term='Json'/><title type='text'>Implementing Ajax with Zend Framework and Json</title><content type='html'>Well, while working with ajax, it better to have an xml as response. Xml, however need more coding and parsing on client side than json.&lt;br /&gt;Zend framework provides very easy way to generate json response.&lt;br /&gt;In this article I’m going to discuss how to create Ajax request using prototype and how to use Zend_Json to generate response.&lt;br /&gt;For generating Ajax request, you will need to write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br /&gt;    new Ajax.Request(&lt;br /&gt;    &amp;quot;url&amp;quot;,&lt;br /&gt;    {&lt;br /&gt;    method: 'post',&lt;br /&gt;    parameters: {'val1': 1, 'val2': 2},&lt;br /&gt;    onComplete: displayResults&lt;br /&gt;}    &lt;br /&gt;);&lt;br /&gt;function displayResults(rsp)&lt;br /&gt;{&lt;br /&gt;    var results = eval('('+rsp.responseText+')');&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;If response is the form of this&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;[&lt;br /&gt;{&amp;quot;firstName&amp;quot;:&amp;quot;Faheem&amp;quot;,&amp;quot;lastName&amp;quot;:&amp;quot;Abbas&amp;quot;,&amp;quot;username&amp;quot;:&amp;quot;fahim&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;faheem.abbas@nxb.com.pk&amp;quot;},&lt;br /&gt;&lt;br /&gt;{&amp;quot;firstName&amp;quot;:&amp;quot;Shazil&amp;quot;,&amp;quot;lastName&amp;quot;:&amp;quot;Hassan&amp;quot;,&amp;quot;username&amp;quot;:&amp;quot;shazil&amp;quot;,&amp;quot;email&amp;quot;:&amp;quot;shazil.hassan@yahoo.com&amp;quot;}&lt;br /&gt;]&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Then to acess the values of the first row, write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;var firstName = results[0].firstName;&lt;br /&gt;var lastName = results[0].lastName;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;and the values of the second row can be accessed as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;var firstName = results[1]. firstName;&lt;br /&gt;var lastName = results[1].lastName;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;To create Json response, you will need to write the following in your controller action&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$users = new Users();&lt;br /&gt;$username = $this-&amp;gt;_getParam('username');&lt;br /&gt;$select = $users-&amp;gt;select();&lt;br /&gt;$data = $users-&amp;gt;fetchAll($select);&lt;br /&gt;$results = $data-&amp;gt;toArray();&lt;br /&gt;echo Zend_Json::encode($results);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Keep in mind that “users” is our model, having the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class Users extends Zend_Db_Table&lt;br /&gt;{&lt;br /&gt;    protected $_name = &amp;quot;users&amp;quot;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;That's it. cheers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-7602979437216063915?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/7602979437216063915/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/implementing-ajax-with-zend-framework.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7602979437216063915'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7602979437216063915'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/implementing-ajax-with-zend-framework.html' title='Implementing Ajax with Zend Framework and Json'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-9046506155146645515</id><published>2009-07-09T22:06:00.000-07:00</published><updated>2009-07-09T22:15:46.323-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><category scheme='http://www.blogger.com/atom/ns#' term='Joomla'/><title type='text'>Joomla component in Zend Framework example</title><content type='html'>Joomla is a nice CMS(content management system) and Zend Framework is once of the famous and widely adopted MVC Framework since its first release. One of the nice thing about Zend is its loosely coupled components.&lt;br /&gt;&lt;br /&gt;Keep in mind that  component in joomla and Zend Framework don’t refer to the same concept. Those who have worked in Joomla and Zend Framework know the difference.&lt;br /&gt;&lt;br /&gt;In this article I’m not going to discuss what Zend and Joomla are all about and how component is different in both, but instead I’m going to share a little secret of how to develop joomla component in Zend Framework.&lt;br /&gt;&lt;br /&gt;This article is not for those who are unaware of joomla and Zend.&lt;br /&gt;&lt;br /&gt;Although joomla has own API for developing its components and modules, but you can use any php code in addition to its own API.&lt;br /&gt;&lt;br /&gt;Reason is simple. Joomla is developed in php.&lt;br /&gt;&lt;br /&gt;As Zend also used php behind the scene, so both can interact easily.&lt;br /&gt;&lt;br /&gt;This was a bit of introduction.&lt;br /&gt;&lt;br /&gt;While discussing all these things I assumed that you have little knowledge of joomla and have some knowledge of Zend Framework as well.&lt;br /&gt;&lt;br /&gt;So let’s dig in.&lt;br /&gt;&lt;br /&gt;Before writing any code you will need to successfully download and install joomla. Also download Zend and save it in the directory of your choice.&lt;br /&gt;&lt;br /&gt;Once successfully installed joomla, open joomla/administrator/components and create a folder called com_yourcomp.&lt;br /&gt;&lt;br /&gt;This is your component folder. You will need to create a file named yourcomp.php&lt;br /&gt;&lt;br /&gt;If you want to add component in your administrator, the name should be admin.yourcomp.php.&lt;br /&gt;&lt;br /&gt;That’s it, you have now created a the necessary directory structure for your joomla component development.&lt;br /&gt;&lt;br /&gt;If you write a line “Hello world!” in youcomp.php or admin.yourcomp.php and browse your page as&lt;br /&gt;&lt;br /&gt;http://localhost/joomla/index.php?option=com_yourcomp&lt;br /&gt;&lt;br /&gt;you will see&lt;br /&gt;&lt;br /&gt;“Hello world” printed.&lt;br /&gt;&lt;br /&gt;These are the minimum requirements for developing joomla component.&lt;br /&gt;&lt;br /&gt;Now we will using Zend Framework classes to add code to this file plus we will create Zend directory structure in order to work with Zend MVC.&lt;br /&gt;&lt;br /&gt;Create following directory structure in your joomla/administrator/components.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_bn44g8iuZbQ/SlbMnoc4UwI/AAAAAAAAADI/V2S_Hi-ZBjo/s1600-h/zend_dir_structure.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 203px; height: 184px;" src="http://3.bp.blogspot.com/_bn44g8iuZbQ/SlbMnoc4UwI/AAAAAAAAADI/V2S_Hi-ZBjo/s320/zend_dir_structure.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5356693788049298178" /&gt;&lt;/a&gt;&lt;br /&gt;Here you can see that my component name is com_advertisers.&lt;br /&gt;&lt;br /&gt;In this directory I’ve&lt;br /&gt;&lt;br /&gt;    * admin.advertiser.php file&lt;br /&gt;    * application directory&lt;br /&gt;    * Joomla directory&lt;br /&gt;&lt;br /&gt;The file admin.advertiser.php will serve as the bootstrap file.&lt;br /&gt;&lt;br /&gt;Application directory contain specific directory for controllers, models and views.&lt;br /&gt;&lt;br /&gt;The most important role is played by our Joomla directory in developing joomla component in Zend Framework.&lt;br /&gt;&lt;br /&gt;This directory contain Controllers/Plugins/Router.php file.&lt;br /&gt;&lt;br /&gt;This file contains code for calling specific action based on particular task. Before going to discuss code in the Router.php file, I’m going to show the code need in our admin.advertisers.php file.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;define('ROOT_DIR', dirname(__FILE__));&lt;br /&gt;set_include_path('.'&lt;br /&gt;    . PATH_SEPARATOR . ROOT_DIR . '/'&lt;br /&gt;    . PATH_SEPARATOR . ROOT_DIR . '/application'&lt;br /&gt;    . PATH_SEPARATOR . ROOT_DIR . '/application/models'&lt;br /&gt;    . PATH_SEPARATOR . get_include_path()&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;require_once &amp;quot;Zend/Controller/Front.php&amp;quot;;&lt;br /&gt;require_once &amp;quot;Joomla/Controllers/Plugins/Router.php&amp;quot;;&lt;br /&gt;&lt;br /&gt;$frontController = Zend_Controller_Front::getInstance();&lt;br /&gt;$frontController-&amp;gt;throwExceptions(true);&lt;br /&gt;&lt;br /&gt;$frontController-&amp;gt;registerPlugin(new Joomla_Controllers_Plugins_Router());&lt;br /&gt;$frontController-&amp;gt;setControllerDirectory(ROOT_DIR.'/application/controllers');&lt;br /&gt;&lt;br /&gt;$frontController-&amp;gt;dispatch();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the first few lines I have included path to our com_advertisers directory, application directory and models directory.&lt;br /&gt;&lt;br /&gt;Next I include Zend Front Controller files and Router.php file. I’ll discuss code in the Router.php file later as it contain the most important code.&lt;br /&gt;&lt;br /&gt;Next I initialize front controller, register Router Plugin class which is defined in our Router.php file, set controller directory and call dispatch.&lt;br /&gt;&lt;br /&gt;That’s it. We have now defined our bootstrap file.&lt;br /&gt;&lt;br /&gt;One important thing is setting path to our library files that contain Zend component.&lt;br /&gt;&lt;br /&gt;You can include path using set_include_path or set it in your php.ini file.&lt;br /&gt;&lt;br /&gt;If you don’t include this path, your application will not work as you expected.&lt;br /&gt;&lt;br /&gt;Now go to controllers directory and create IndexController.php and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;require_once('Zend/Controller/Action.php');&lt;br /&gt;class IndexController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;    public function indexAction()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;    public function editAction()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;    public function saveAction()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Noting special here. I’ve created only three actions.&lt;br /&gt;&lt;br /&gt;Go to your application/views/scripts directory and create directory called index and create three files index.phtml, edit.phtml and save.phtml.&lt;br /&gt;&lt;br /&gt;The code above is what you will need to work with Zend Framework MVC. In order to integrate this code with joomla will need one additional files. In my case the file is Router.php&lt;br /&gt;&lt;br /&gt;I have create this file in com_advertiser/Joomla/Controllers/Plugins/ directory.&lt;br /&gt;&lt;br /&gt;The code contain in this file is&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;require_once('Zend/Controller/Plugin/Abstract.php');&lt;br /&gt;class Joomla_Controllers_Plugins_Router extends Zend_Controller_Plugin_Abstract&lt;br /&gt;{&lt;br /&gt;    public function preDispatch(Zend_Controller_Request_Abstract $request)&lt;br /&gt;    {&lt;br /&gt;        $task = $request-&amp;gt;getParam('task')&lt;br /&gt;        switch($task) {&lt;br /&gt;            case 'edit':&lt;br /&gt;                $request-&amp;gt;setActionName('edit');&lt;br /&gt;                break;&lt;br /&gt;            case 'save':&lt;br /&gt;                $request-&amp;gt;setActionName('save');&lt;br /&gt;                break;&lt;br /&gt;            default:&lt;br /&gt;                $request-&amp;gt;setActionName('index');&lt;br /&gt;                break;&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;First I’ve include plugin class and then extended my Router class from Zend_Controller_Plugin_Abstract.&lt;br /&gt;&lt;br /&gt;This Zend_Controller_Plugin_Abstract class contain a method preDispatch that is called before any controller is called in the routing process.&lt;br /&gt;&lt;br /&gt;In the preDispatch method, I get the param “task” and write a switch statement to check this param. If it is edit, I give control to my editAction of the default IndexController. And similarly if it is save, I route request to my saveAction and by default, if no parameter is specified, the request will be dispatched to indexAction of my IndexController.&lt;br /&gt;&lt;br /&gt;That’s it.&lt;br /&gt;&lt;br /&gt;Now if you write&lt;br /&gt;&lt;br /&gt;http://localhost/joomla/administrator/index.php?option=com_advertisers&amp;task=save&lt;br /&gt;&lt;br /&gt;It will show what ever you have written in your save.phtml file.&lt;br /&gt;&lt;br /&gt;And similarly if you write&lt;br /&gt;&lt;br /&gt;http://localhost/joomla/administrator/index.php?option=com_advertisers&amp;task=edit&lt;br /&gt;&lt;br /&gt;it will route you to editAction and will display whatever you have define there.&lt;br /&gt;&lt;br /&gt;Any question and suggestion are welcomed.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-9046506155146645515?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/9046506155146645515/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/joomla-component-in-zend-framework.html#comment-form' title='18 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/9046506155146645515'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/9046506155146645515'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/joomla-component-in-zend-framework.html' title='Joomla component in Zend Framework example'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_bn44g8iuZbQ/SlbMnoc4UwI/AAAAAAAAADI/V2S_Hi-ZBjo/s72-c/zend_dir_structure.jpg' height='72' width='72'/><thr:total>18</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-1539040265747728058</id><published>2009-07-06T10:07:00.000-07:00</published><updated>2009-07-06T10:13:06.367-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Framework: Zend_Config examples</title><content type='html'>Zend_Config is used to simply access to, and use of configuration data in Zend Framework application.&lt;br /&gt;Zend_Config currently provide adapters for getting configuration data from xml and ini files. You can also store configuration data in array and pass that array to the Zend_Config constructore, this however is not a recommended way. Configuration data is mostly stored in either xml files or ini files.&lt;br /&gt;In this tutorial I am going to put shad on the usage of Zend_Config and will give you example of how to keep data in array, ini and xml file and then use that using Zend_Config.&lt;br /&gt;So let’s have a look.&lt;br /&gt;To hold configuration data in form of array, you will need to write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$configArray = array(&lt;br /&gt;    'database' =&amp;gt; array(&lt;br /&gt;        'adapter' =&amp;gt; 'pdo_mysql',&lt;br /&gt;        'params'  =&amp;gt; array(&lt;br /&gt;            'host'     =&amp;gt; localhost',&lt;br /&gt;            'username' =&amp;gt; 'user_name',&lt;br /&gt;            'password' =&amp;gt; 'user_password',&lt;br /&gt;            'dbname'   =&amp;gt; 'database_name'&lt;br /&gt;        )&lt;br /&gt;    )&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;You can clearly see that we have defined an associative array containing database information.&lt;br /&gt;Now as you have defined an array having configuration information, next step is to create an object of Zend_Config class passing the above array. The code will look like the following&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$config = new Zend_Config($configArray);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now, if you want to make database configuration, simply write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$db= Zend_Db::factory($config-&amp;gt;database);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;To store the above information in ini file, create config.ini somewhere in your application directory structure, and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;[development]&lt;br /&gt;&lt;br /&gt;database.adapter         = pdo_mysql&lt;br /&gt;database.params.host     = localhost &lt;br /&gt;database.params.username = user_name&lt;br /&gt;database.params.password = user_password&lt;br /&gt;database.params.dbname   = database_name&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;After defining ini file, simply write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$config = new Zend_Config_Ini(&amp;#8216;path/to/ini/config.ini&amp;#8217;,&amp;#8217; development&amp;#8217;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;in your application.&lt;br /&gt;&lt;br /&gt;The database configuration is same as we done earlier.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$db = Zend_Config::factory($config-&amp;gt;database);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Similarly if you like to use, xml file for you application configuration, create config.xml somewhere in your application directory structure and write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?xml version=&amp;quot;1.0&amp;quot;?&amp;gt;&lt;br /&gt;&amp;lt; development &amp;gt;&lt;br /&gt;    &amp;lt;database&amp;gt;&lt;br /&gt;        &amp;lt;adapter&amp;gt;pdo_mysql&amp;lt;/adapter&amp;gt;&lt;br /&gt;            &amp;lt;params&amp;gt;&lt;br /&gt;                &amp;lt;host&amp;gt;db.example.com&amp;lt;/host&amp;gt;&lt;br /&gt;                &amp;lt;username&amp;gt;dbuser&amp;lt;/username&amp;gt;&lt;br /&gt;                &amp;lt;password&amp;gt;secret&amp;lt;/password&amp;gt;&lt;br /&gt;                &amp;lt;dbname&amp;gt;dbname&amp;lt;/dbname&amp;gt;&lt;br /&gt;            &amp;lt;/params&amp;gt;&lt;br /&gt;    &amp;lt;/databse&amp;gt;&lt;br /&gt;&amp;lt;/ development &amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now either in your bootstrap file or where you want to initialize configuration, write&lt;br /&gt;$config = new Zend_Config_Xml(‘path/to/xml/config.xml’,’development’);&lt;br /&gt;For database configuration, simply write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$db = Zend_Db::factory($config-&amp;gt;database);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;That's it. cheers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-1539040265747728058?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/1539040265747728058/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-zendconfig-examples.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/1539040265747728058'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/1539040265747728058'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-zendconfig-examples.html' title='Zend Framework: Zend_Config examples'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-2524653793355785973</id><published>2009-07-05T23:29:00.000-07:00</published><updated>2009-07-05T23:32:32.645-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Creating radio button in Zend Framework</title><content type='html'>Zend Framework Form: working with radio buttons&lt;br /&gt;I have already discussed creation of Zend_From in my previous articles. In this article I'd discuss how to work&lt;br /&gt;with radio buttons in Zend Framework Form.&lt;br /&gt;&lt;br /&gt;In your Zend_Form, radio buttons can be created using two methods.&lt;br /&gt;The first one is&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class CustomForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;        $this-&amp;gt;setAction('user/process');&lt;br /&gt;        &lt;br /&gt;        $gender = $this-&amp;gt;createElement('radion','gender');&lt;br /&gt;        $gender-&amp;gt;setLabel('Gender:')&lt;br /&gt;            -&amp;gt;addMultiOptions(array(&lt;br /&gt;                    'male' =&amp;gt; 'Male',&lt;br /&gt;                    'female' =&amp;gt; 'Female' &lt;br /&gt;                        ))&lt;br /&gt;            -&amp;gt;setSeparator('');    &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the above code we first create our form by extending it from Zend_Form, override its init() method and setting its method and action attributes.&lt;br /&gt;Next we create our radio button as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$gender = $this-&amp;gt;createElement('radion','gender');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here first argument specify that we want to create radion button element of the form and the second argument set the name&lt;br /&gt;and id of the radio button element group. In the next line we call addMultiOptions() method giving its array of optional&lt;br /&gt;values. and lost but not least, I am calling method setSeparator for placing both radio buttons on the same line. If this&lt;br /&gt;setSeparator method is not called, each radion button will appear on separate line.&lt;br /&gt;&lt;br /&gt;The above radio button can also be created as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class CustomForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;        $this-&amp;gt;setAction('user/process');&lt;br /&gt;        &lt;br /&gt;        $gender = new Zend_Form_Element_Radio('gender');&lt;br /&gt;        $gender-&amp;gt;setLabel('Gender:')&lt;br /&gt;            -&amp;gt;addMultiOptions(array(&lt;br /&gt;                    'male' =&amp;gt; 'Male',&lt;br /&gt;                    'female' =&amp;gt; 'Female' &lt;br /&gt;                        ))&lt;br /&gt;            -&amp;gt;setSeparator('');    &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The only difference in the above two example is that I have placed&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$gender = $this-&amp;gt;createElement('radion','gender'); &lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;With&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$gender = new Zend_Form_Element_Radio('gender');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Both statements give the same result.&lt;br /&gt;&lt;br /&gt;For setting different radio button options, you can also use the following method.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$gender-&amp;gt;addMultiOption(&amp;#8216;male&amp;#8217;,&amp;#8217;Male&amp;#8217;);&lt;br /&gt;$gender-&amp;gt;addMultiOption(&amp;#8216;female&amp;#8217;,&amp;#8217;Female&amp;#8217;);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-2524653793355785973?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/2524653793355785973/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-radio-button-in-zend-framework.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/2524653793355785973'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/2524653793355785973'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-radio-button-in-zend-framework.html' title='Creating radio button in Zend Framework'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-6508136036329194695</id><published>2009-07-05T22:56:00.001-07:00</published><updated>2009-07-05T23:06:34.204-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Ajax with Json and prototype in Zend Framework</title><content type='html'>I used JSon for the first time in my application today. Zend provide a very easy way to create JSon response.&lt;br /&gt;In this article I would use Prototype to make ajax call. Hopefully you will now a bit about Prototype. Anyway if not, it would not be a hard job to understand it after reading my article.&lt;br /&gt;So let’s get started.&lt;br /&gt;Consider you have the following form.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_bn44g8iuZbQ/SlGSbGk5YCI/AAAAAAAAADA/LcT_YEc1Cik/s1600-h/Ajax+Form.JPG"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 294px; height: 181px;" src="http://1.bp.blogspot.com/_bn44g8iuZbQ/SlGSbGk5YCI/AAAAAAAAADA/LcT_YEc1Cik/s320/Ajax+Form.JPG" border="0" alt=""id="BLOGGER_PHOTO_ID_5355222426239721506" /&gt;&lt;/a&gt;&lt;br /&gt;The scenario is&lt;br /&gt;When user select name from the dropdown, the entire form is filled with the data from the database for that particular user.&lt;br /&gt;&lt;br /&gt;For this purpose you would need to have a controller/Action(s), a model and template file.&lt;br /&gt;In your form attach the following attrib to your name element as&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;$name = $this-&amp;gt;createElement('select','name');&lt;br /&gt;$name-&amp;gt;addMultioptions(array(&lt;br /&gt;                    'select'=&amp;gt;'[select]',&lt;br /&gt;                    '1' =&amp;gt; 'Faheem',&lt;br /&gt;                    '2' =&amp;gt; 'Abbas'&lt;br /&gt;));&lt;br /&gt;&lt;br /&gt;$name-&amp;gt;setAttrib('onchange','AutoFill()');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the lines above we first create a dropdown give it two values. And then attach javascript function “AutoFill” function using setAttrib method.&lt;br /&gt;&lt;br /&gt;In your controller initialize your form and assign it to the view template as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$form = new MyCustomForm();&lt;br /&gt;$this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now in your view template file write the following.&lt;br /&gt;Write the following javascript code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br /&gt;    function AutoFill()&lt;br /&gt;    {&lt;br /&gt;        new Ajax.Request(&lt;br /&gt;        &amp;quot;&amp;lt;?=$this-&amp;gt;url(array('controller'=&amp;gt;'user','action'=&amp;gt;'getdata'))?&amp;gt;&amp;quot;,&lt;br /&gt;            {&lt;br /&gt;                method:'get',&lt;br /&gt;                parameters: {id: value},&lt;br /&gt;                onSuccess: FillForm&lt;br /&gt;        }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;function FillForm(rsp)&lt;br /&gt;{&lt;br /&gt;    var card = eval('(' + rsp.responseText + ')');&lt;br /&gt;    $('address1').value = card.items[0].address1;&lt;br /&gt;    $('address2').value = card.items[0].address2;&lt;br /&gt;    $('postalcode').value = card.items[0].postalcode;&lt;br /&gt;} &lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;To get response you will need to create an action and write the following code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class User extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;    public function indexAction()&lt;br /&gt;    {&lt;br /&gt;        $form = new MyCustomForm();&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    public function getdataAction()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;_helper-&amp;gt;layout()-&amp;gt;disableLayout();&lt;br /&gt;        $users = new Users();&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;_helper-&amp;gt;viewRenderer-&amp;gt;setNoRender();&lt;br /&gt;        if ($this-&amp;gt;getRequest()-&amp;gt;isXmlHttpRequest()) {&lt;br /&gt;            $id = $this-&amp;gt;_getParam('id');&lt;br /&gt;            $userData = $ users -&amp;gt;getData($id);&lt;br /&gt;            $dojoData= new Zend_Dojo_Data('id',$userData,'id');&lt;br /&gt;            echo $dojoData-&amp;gt;toJson();&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the above code getdataAction is called using ajax call. In the first line we have disabled the layout, because we don’t need layout in case of ajax response. Next we create object of our model class(discussed later). Next we tell zend to disable view rendering.&lt;br /&gt;In the next few lines we check for ajax request, get id, call our getData model method.&lt;br /&gt;We then create dojo data object. This object provide a very useful method to convert data retrieved into json format. The method used is toJson().&lt;br /&gt;&lt;br /&gt;In our model we have code like the following.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class Users extends Zend_Db_Table&lt;br /&gt;{&lt;br /&gt;    protected $_name = 'users';&lt;br /&gt;    &lt;br /&gt;    public function getData($id)&lt;br /&gt;    {&lt;br /&gt;        $select = $this-&amp;gt;_db-&amp;gt;select()&lt;br /&gt;                        -&amp;gt;from($this-&amp;gt;_name,&lt;br /&gt;                                    array('address1','address2'&amp;#8230;.))&lt;br /&gt;                        -&amp;gt;where('id = ?', $id);&lt;br /&gt;        $result = $this-&amp;gt;getAdapter()-&amp;gt;fetchAll($select);&lt;br /&gt;        return $result;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;That's it. Cheers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-6508136036329194695?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/6508136036329194695/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/ajax-with-json-and-prototype-in-zend.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6508136036329194695'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6508136036329194695'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/ajax-with-json-and-prototype-in-zend.html' title='Ajax with Json and prototype in Zend Framework'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://1.bp.blogspot.com/_bn44g8iuZbQ/SlGSbGk5YCI/AAAAAAAAADA/LcT_YEc1Cik/s72-c/Ajax+Form.JPG' height='72' width='72'/><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-7474097849112812300</id><published>2009-07-05T22:44:00.000-07:00</published><updated>2009-07-05T23:08:03.771-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>select box in Zend framework: code and example</title><content type='html'>Though I’ve already discuss how to create dropdown in one of my previous article, however here I would discuss it a bit in detail.&lt;br /&gt;&lt;br /&gt;You can create it using the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class CustomForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;        $this-&amp;gt;setAction('user/process');&lt;br /&gt;        &lt;br /&gt;        $country = $this-&amp;gt;createElement('select',&amp;#8217;countries&amp;#8217;);&lt;br /&gt;        $country -&amp;gt;setLabel('Countries:')&lt;br /&gt;            -&amp;gt;addMultiOptions(array(&lt;br /&gt;                    'US' =&amp;gt; 'United States',&lt;br /&gt;                    'UK' =&amp;gt; 'United Kingdom' &lt;br /&gt;                        ));    &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Or can also be created using the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class CustomForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;        $this-&amp;gt;setAction('user/process');&lt;br /&gt;        &lt;br /&gt;        $country = new Zend_Form_Element_Select('countries');&lt;br /&gt;        $country -&amp;gt;setLabel('Countries:')&lt;br /&gt;            -&amp;gt;addMultiOptions(array(&lt;br /&gt;                    'US' =&amp;gt; 'United States',&lt;br /&gt;                    'UK' =&amp;gt; 'United Kingdom' &lt;br /&gt;                        ));    &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The options are hard code in both of the cases. This will not be requirement always.&lt;br /&gt;Sometime or most of the time application need that drop down should be populated fetching records from the data base. So for this purpose I would like to implement the following code.&lt;br /&gt;Fist in your model write the following.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class Countries extends Zend_Table&lt;br /&gt;{&lt;br /&gt;    protected $_name = 'countries';&lt;br /&gt;    public function getCountriesList()&lt;br /&gt;    {&lt;br /&gt;        $select  = $this-&amp;gt;_db-&amp;gt;select()&lt;br /&gt;                            -&amp;gt;from($this-&amp;gt;_name,&lt;br /&gt;                    array('key' =&amp;gt; 'id','value' =&amp;gt; 'country_name'))&lt;br /&gt;        $result = $this-&amp;gt;getAdapter()-&amp;gt;fetchAll($select);&lt;br /&gt;        return $result;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Keep in mind that the records we fetch will have an associated array having id as key and country name as value. If you don’t defined the above array, array(‘key’ =&gt; ’id’,’value’ =&gt; ‘country_name’), as I have defined, you will not get what you want. So be careful while fetching records for constructing drop down.&lt;br /&gt;&lt;br /&gt;And now in your form write the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class CustomForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;        $this-&amp;gt;setAction('user/process');&lt;br /&gt;        &lt;br /&gt;        $countries = new Countries();&lt;br /&gt;        $countries_list = $countires-&amp;gt;getCountriesList();        &lt;br /&gt;&lt;br /&gt;        $country = new Zend_Form_Element_Select('countries');&lt;br /&gt;        $country -&amp;gt;setLabel('Countries:')&lt;br /&gt;            -&amp;gt;addMultiOptions( $countriesList &lt;br /&gt;                        ));    &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the above code the only thing changes is&lt;br /&gt;1. I have instantiated model  using&lt;br /&gt;$countries  =  new Countries();&lt;br /&gt;&lt;br /&gt;2. Call getCountiresList() method. And assign the list to the instead of assign hard coded values.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-7474097849112812300?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/7474097849112812300/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/select-box-in-zend-framework-code-and.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7474097849112812300'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7474097849112812300'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/select-box-in-zend-framework-code-and.html' title='select box in Zend framework: code and example'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-3529497007380707332</id><published>2009-07-05T05:21:00.000-07:00</published><updated>2009-07-05T05:29:42.478-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Sending Email with attachment in Zend Framework</title><content type='html'>You may have used Php for sending emails in your application. I haven’t experienced it in plain php, so I don’t know whether its easy or difficult. I, however, know that Zend Framework provide very easy way for sending emails. You can even attach files with your email with single method call.&lt;br /&gt;In this article I am going to discuss how to send email with attachments. Please do tell me whether it helped you or not.&lt;br /&gt;&lt;br /&gt;In your controller, write something like this.&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$emial_body = “&amp;lt;table&amp;gt;&amp;lt;tr&amp;gt;&amp;lt;td&amp;gt;Body of the email&amp;lt;/td&amp;gt;&amp;lt;/tr&amp;gt;&amp;lt;/table”;&lt;br /&gt;&lt;br /&gt;$mail = new Zend_Mail();&lt;br /&gt;$mail-&amp;gt;setType(Zend_Mime::MULTIPART_RELATED);&lt;br /&gt;$mail-&amp;gt;setBodyHtml($email_body);&lt;br /&gt;$mail-&amp;gt;setFrom('support@example.com', 'Example');&lt;br /&gt;$mail-&amp;gt;addTo('user@abc.com', 'Username');&lt;br /&gt;$mail-&amp;gt;setSubject('Sending email using Zend Framework');&lt;br /&gt;$mail-&amp;gt;send();&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This, although, will send email, however it’s not a good approach to create email in your controller as your mail body may contain thousands of words.&lt;br /&gt;&lt;br /&gt;The best approach is to create a template, that contain the contents that will act as body of the email. To achieve this, create a file called emailExample.phtml in your /application/views/scripts/templates/ directory. And write the contents you want to put, those contents will serve as body of the email you are going to send.&lt;br /&gt;&lt;br /&gt;I am having the following code in my emailExample.phtml&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;!DOCTYPE html PUBLIC &amp;quot;-//W3C//DTD XHTML 1.0 Transitional//EN&amp;quot; &amp;quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;html xmlns=&amp;quot;http://www.w3.org/1999/xhtml&amp;quot;&amp;gt;&lt;br /&gt;&amp;lt;body&amp;gt;&lt;br /&gt;    &amp;lt;table&amp;gt;&lt;br /&gt;    &amp;lt;tr&amp;gt;&lt;br /&gt;        &amp;lt;td&amp;gt;&lt;br /&gt;            all my contents here.&lt;br /&gt;        &amp;lt;/td&amp;gt;&lt;br /&gt;    &amp;lt;/tr&amp;gt;&lt;br /&gt;    &amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Now in your controller, write&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$myView = new Zend_View();&lt;br /&gt;$myView-&amp;gt;addScriptPath(ROOT_DIR . '/application/views/scripts/templates/');&lt;br /&gt;$html_body = $ myView -&amp;gt;render(emailExample.phtml');&lt;br /&gt;&lt;br /&gt;$mail = new Zend_Mail();&lt;br /&gt;$mail-&amp;gt;setType(Zend_Mime::MULTIPART_RELATED);&lt;br /&gt;$mail-&amp;gt;setBodyHtml($html_body);&lt;br /&gt;&lt;br /&gt;$mail-&amp;gt;setFrom('support@example.com', 'Example');&lt;br /&gt;$mail-&amp;gt;addTo('user@abc.com', 'Username');&lt;br /&gt;$mail-&amp;gt;setSubject('Sending email using Zend Framework');&lt;br /&gt;$mail-&amp;gt;send();&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here we are first creating an instance of Zend_View, call addScriptPath() to add script path- directory path where our template file reside and which serve as body of our email.&lt;br /&gt;We then get the template by calling render() method on that view object, giving it the name of the template. The rest of the process is same, creating Zend_Mail object, setting body and so on.&lt;br /&gt;Another question come to mind is how&lt;br /&gt;to send an attachment?&lt;br /&gt;This is pretty simple too.&lt;br /&gt;First you will need to get the contents of the file, by calling a method file_get_contents(), like this.&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$fileContents = file_get_contents(‘path/to/file’);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;And then call a simple method called createAttachment (), as&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$file = $mail-&amp;gt;createAttachment($fileContents);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;And set the name of the attachment as&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$file-&amp;gt;filename = "yourfile.doc";&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;That’s it. Cheers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-3529497007380707332?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/3529497007380707332/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/sending-email-with-attachment-in-zend.html#comment-form' title='11 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/3529497007380707332'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/3529497007380707332'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/sending-email-with-attachment-in-zend.html' title='Sending Email with attachment in Zend Framework'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>11</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-8206352427089435209</id><published>2009-07-04T03:48:00.000-07:00</published><updated>2010-10-29T02:52:35.152-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork tutorial'/><title type='text'>Zend Framework building complete application</title><content type='html'>Well, I have written lots of separate article on Zend Framework. Hopefully most of folk out there searching for valuable help may have gotten some from my articles.&lt;br /&gt;This time my objective is to share everything with you, from basic configuration till to building complete Zend Framework application.&lt;br /&gt;This article will cover&lt;br /&gt;1. How to make initial configuration.&lt;br /&gt;2. How to use Zend_Auth for authentication&lt;br /&gt;3. Using Zend_Session for handling sessions&lt;br /&gt;4. What are models and how to create them&lt;br /&gt;5. Using Zend_Db to handle backend database for storing valuable information.&lt;br /&gt;And much more.&lt;br /&gt;So let’s get started.&lt;br /&gt;1. Creating directory structure and making initial configuration&lt;br /&gt;Zend Framework is based on MVC design patterns. MVC stands for Model, View, Controller. A simple definition of MVC design pattern is to separate business logic from presentation logic.&lt;br /&gt;In order to work with Zend Framework MVC design pattern, you’ll need to make necessary directory structure. There are various ways of making directory structure, I, however will use the most easier to create and understand structure.&lt;br /&gt;&lt;br /&gt;The structure I created is.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;html_root&lt;br /&gt;   /application&lt;br /&gt;       /controllers&lt;br /&gt;           IndexController.php&lt;br /&gt;       /models&lt;br /&gt;           Users.php&lt;br /&gt;       /forms&lt;br /&gt;           LoginForm.php&lt;br /&gt;       /views&lt;br /&gt;           /scripts&lt;br /&gt;               /dojo&lt;br /&gt;                   index.phtml&lt;br /&gt;   /libaray&lt;br /&gt;       /Zend&lt;br /&gt;/js&lt;br /&gt;   /css&lt;br /&gt;   /images&lt;br /&gt;   /index.phtm&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;On the top level we have html_root directory, containing application directory, library, js, css and images. It also contain index.phtml called our bootstrap file. This file contain all our configuration code. Further more application directory contain controller, models forms and views directories. Library  directory contains Zend components. Js contain all our js files, css contains css files and images contains all images used in our application.&lt;br /&gt;On the hard drive our directory structure looks like&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_bn44g8iuZbQ/Sk8z9pxDNNI/AAAAAAAAAC4/jmo5rt-lYN8/s1600-h/zend_mvc_directory_structure.JPG"&gt;&lt;img style="cursor: pointer; width: 208px; height: 224px;" src="http://3.bp.blogspot.com/_bn44g8iuZbQ/Sk8z9pxDNNI/AAAAAAAAAC4/jmo5rt-lYN8/s320/zend_mvc_directory_structure.JPG" alt="" id="BLOGGER_PHOTO_ID_5354555616243430610" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;Keep in mind that controllers directory contain our entire controllers, form directory contain all forms used in our application. Model contains php files contain our business logic. Views/scripts contain template files against each controllers.&lt;br /&gt;&lt;br /&gt;Now as we have made necessary directory structure, next step is to make necessary configuration in our bootstrap file.&lt;br /&gt;2. Making necessary configuration in our bootstrap- index.php file.&lt;br /&gt;The most important file, that will get all request and route them to specific controllers. It contain code for setting include path, initializing front controller, set controllers path and call dispatch method.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;define('ROOT_DIR', dirname(__FILE__));&lt;br /&gt;&lt;br /&gt;set_include_path('.'&lt;br /&gt;. PATH_SEPARATOR . ROOT_DIR . '/library'&lt;br /&gt;. PATH_SEPARATOR . ROOT_DIR . '/application/models'&lt;br /&gt;. PATH_SEPARATOR . ROOT_DIR . '/application/forms'&lt;br /&gt;. PATH_SEPARATOR . get_include_path()&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;require_once "Zend/Loader/Autoloader.php";&lt;br /&gt;$autoloader = Zend_Loader_Autoloader::getInstance();&lt;br /&gt;$autoloader-&gt;setFallbackAutoloader(true);&lt;br /&gt;&lt;br /&gt;$frontController = Zend_Controller_Front::getInstance();&lt;br /&gt;&lt;br /&gt;$frontController-&amp;gt;throwExceptions(true);&lt;br /&gt;&lt;br /&gt;$frontController-&amp;gt;setControllerDirectory(ROOT_DIR.'/application/controllers');&lt;br /&gt;$frontController-&amp;gt;dispatch();&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The code is very simple to explain. The first line define path to our root directory.&lt;br /&gt;The next lines set include path to /library, /application/models and /application/forms.&lt;br /&gt;&lt;br /&gt;Next lines are very important&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;require_once "Zend/Loader.php";&lt;br /&gt;Zend_Loader::registerAutoload();&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Help in loading all php files we need in our application. If we don’t use this code, we will need to include require_once statement to load php files needed.&lt;br /&gt;&lt;br /&gt;In next lines we get instance of the front controller, set controllers directory and call dispatch method.&lt;br /&gt;Front controller is responsible for handling the user request. It takes the request and on specific criteria take appropriate action.&lt;br /&gt;That’s it. Its our configuration file. Simple and easy.&lt;br /&gt;&lt;br /&gt;3. Creating controllers and views&lt;br /&gt;In html_root/application/controllers, create IndexController.php and put the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class IndexController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;   public function indexAction()&lt;br /&gt;   {&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Every controller must be extended from Zend_Controller_Action and can contain as many methods as possible. Method defined in controllers is called action. Once you create action in the controller, next step is to create view template. For this purpose, in html_root/application/views/scripts/, create index/index.phtml and put the following code in it.&lt;br /&gt;&lt;h5&gt; Hello world&lt;/h5&gt;&lt;br /&gt;&lt;br /&gt;That’s it.&lt;br /&gt;Now if you browse&lt;br /&gt;http://localhost/html_root/&lt;br /&gt;&lt;br /&gt;You will see&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Hello World &lt;/span&gt;&lt;br /&gt;If you don’t see “Hello world” printed, read the above guide lines again.&lt;br /&gt;As we have now successfully created directory structure and bootstrap file, its time to make other necessary configuration for database.&lt;br /&gt;&lt;br /&gt;4. Configuration for working with database&lt;br /&gt;How a web application can be completed without usage of database. Different web application uses different database. Some uses Mysql, other SQLite, SQL server and Oracle. One of the nice thing about Zend Framework is that it support multiple database servers.&lt;br /&gt;Here we are going to making configuration for Mysql server.&lt;br /&gt;For database configuration, first create config.ini in html_root/application/ and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;[general]&lt;br /&gt;db.adapter = PDO_MYSQL&lt;br /&gt;db.params.host = localhost&lt;br /&gt;db.params.username = root&lt;br /&gt;db.params.password =&lt;br /&gt;db.params.dbname = zend&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now in your bootstrap file make the following changes.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;define('ROOT_DIR', dirname(__FILE__));&lt;br /&gt;&lt;br /&gt;set_include_path('.'&lt;br /&gt;. PATH_SEPARATOR . ROOT_DIR . '/library'&lt;br /&gt;. PATH_SEPARATOR . ROOT_DIR . '/application/models'&lt;br /&gt;. PATH_SEPARATOR . ROOT_DIR . '/application/forms'&lt;br /&gt;. PATH_SEPARATOR . get_include_path()&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;require_once "Zend/Loader.php";&lt;br /&gt;Zend_Loader::registerAutoload();&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;$config = new Zend_Config_Ini(ROOT_DIR.'/application/config.ini', 'general');&lt;br /&gt;$db = Zend_Db::factory($config-&amp;gt;db);&lt;br /&gt;Zend_Db_Table::setDefaultAdapter($db);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;$frontController = Zend_Controller_Front::getInstance();&lt;br /&gt;$frontController-&amp;gt;throwExceptions(true);&lt;br /&gt;$frontController-&amp;gt;setControllerDirectory(ROOT_DIR.'/application/controllers');&lt;br /&gt;$frontController-&amp;gt;dispatch();&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;First we load our config.ini file that contain our database configuration. Next we call static factory method of Zend_Db giving it $config-&gt;db for database configuration and at the end we set default adapter for our database tables.&lt;br /&gt;That’s it. We have now done all necessary configurations.&lt;br /&gt;Next step is to store and retrieve data from database&lt;br /&gt;5. Working with database data&lt;br /&gt;Now we are going to make an application that will save, display and edit data in the database.&lt;br /&gt;First execute the following query.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;CREATE TABLE `users` (&lt;br /&gt;`id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,&lt;br /&gt;`firstName` VARCHAR( 50 ) NOT NULL ,&lt;br /&gt;`lastName` VARCHAR( 50 ) NOT NULL ,&lt;br /&gt;`username` VARCHAR( 50 ) NOT NULL ,&lt;br /&gt;`email` VARCHAR( 100 ) NOT NULL ,&lt;br /&gt;`password` VARCHAR( 50 ) NOT NULL&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This query create a table called users in the database.&lt;br /&gt;Next step is to create model against this table. In your html_root/application/models/ create Users.php and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class Users extends Zend_Db_Table&lt;br /&gt;{&lt;br /&gt;   protected $_name = "users";&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The only thing we have done is extend our Zend_Db_Table and define name of the model. This name must be same as the database table name.&lt;br /&gt;Now in your html_root/application/controllers/IndexController.php, write&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class IndexController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;   public function indexAction()&lt;br /&gt;   {&lt;br /&gt;       $users = new Users();&lt;br /&gt;       $data = $users-&amp;gt;fetchAll($users-&amp;gt;select());&lt;br /&gt;       $this-&amp;gt;view-&amp;gt;data = $data;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;After making changes in IndexController.php, next step is to make changes in html_root/application/views/scripts/index/index.phtml. write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;List of users&amp;lt;/h4&amp;gt;&lt;br /&gt;&amp;lt;h5&amp;gt;&amp;lt;a href="add" style="color:blue"&amp;gt;Add new user&amp;lt;/a&amp;gt;&amp;lt;/h5&amp;gt;&lt;br /&gt;&amp;lt;table border="1"&amp;gt;&lt;br /&gt;   &amp;lt;thead&amp;gt;   &lt;br /&gt;       &amp;lt;tr&amp;gt;&lt;br /&gt;           &amp;lt;th&amp;gt;First Name&amp;lt;/th&amp;gt;&lt;br /&gt;           &amp;lt;th&amp;gt;Last Name&amp;lt;/th&amp;gt;&lt;br /&gt;           &amp;lt;th&amp;gt;Username&amp;lt;/th&amp;gt;&lt;br /&gt;           &amp;lt;th&amp;gt;Email&amp;lt;/th&amp;gt;&lt;br /&gt;           &amp;lt;th&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;       &amp;lt;/tr&amp;gt;&lt;br /&gt;   &amp;lt;/thead&amp;gt;&lt;br /&gt;   &amp;lt;tboody&amp;gt;&lt;br /&gt;       &amp;lt;?php foreach ($this-&amp;gt;data as $d) {?&amp;gt;&lt;br /&gt;       &amp;lt;tr&amp;gt;&lt;br /&gt;           &amp;lt;td&amp;gt;&amp;lt;?=$d['firstName']?&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;           &amp;lt;td&amp;gt;&amp;lt;?=$d['lastName']?&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;           &amp;lt;td&amp;gt;&amp;lt;?=$d['username']?&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;           &amp;lt;td&amp;gt;&amp;lt;?=$d['email']?&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;           &amp;lt;td&amp;gt;&amp;lt;a href="edit/id/&amp;lt;?=$d['id']?&amp;gt;" style="color:blue"&amp;gt;Edit&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;       &amp;lt;/tr&amp;gt;&lt;br /&gt;       &amp;lt;?php }?&amp;gt;&lt;br /&gt;   &amp;lt;/tbody&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This will show the list of users.&lt;br /&gt;Next we are going to create a form for adding data to users table.&lt;br /&gt;In your html_root/application/forms/ create CustomForm.php and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class CustomForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;   public function init()&lt;br /&gt;   {&lt;br /&gt;       $this-&amp;gt;setMethod('post');&lt;br /&gt;       //$this-&amp;gt;setAction('add');&lt;br /&gt;&lt;br /&gt;       $id = $this-&amp;gt;createElement('hidden','id');&lt;br /&gt;       $firstname = $this-&amp;gt;createElement('text','firstname');&lt;br /&gt;       $firstname-&amp;gt;setLabel('First Name:')&lt;br /&gt;                   -&amp;gt;setAttrib('size',50);&lt;br /&gt;       $lastname = $this-&amp;gt;createElement('text','lastname');&lt;br /&gt;       $lastname-&amp;gt;setLabel('Last Name:')&lt;br /&gt;               -&amp;gt;setAttrib('size',50);&lt;br /&gt;       $username = $this-&amp;gt;createElement('text','username');&lt;br /&gt;       $username-&amp;gt;setLabel('Username:')&lt;br /&gt;               -&amp;gt;setAttrib('size',50);&lt;br /&gt;       $email = $this-&amp;gt;createElement('text','email');&lt;br /&gt;       $email-&amp;gt;setLabel('Email:')&lt;br /&gt;               -&amp;gt;setAttrib('size',50);&lt;br /&gt;       $password = $this-&amp;gt;createElement('password','password');&lt;br /&gt;       $password-&amp;gt;setLabel('Password:')&lt;br /&gt;                   -&amp;gt;setAttrib('size',50);&lt;br /&gt;&lt;br /&gt;       $password2 = $this-&amp;gt;createElement('password','password2');&lt;br /&gt;       $password2-&amp;gt;setLabel('Confirm Password::')&lt;br /&gt;                   -&amp;gt;setAttrib('size',50);&lt;br /&gt;       $register = $this-&amp;gt;createElement('submit','register');&lt;br /&gt;       $register-&amp;gt;setLabel("Register")&lt;br /&gt;               -&amp;gt;setIgnore(true);&lt;br /&gt;&lt;br /&gt;       $this-&amp;gt;addElements(array(&lt;br /&gt;           $firstname,&lt;br /&gt;           $lastname,&lt;br /&gt;           $username,&lt;br /&gt;           $email,&lt;br /&gt;           $password,&lt;br /&gt;           $password2,&lt;br /&gt;           $id,&lt;br /&gt;           $register&lt;br /&gt;       ));&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;We have successfully created our form, next we are going to write necessary code in our IndexController.php&lt;br /&gt;Write the following code in it&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class IndexController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;   public function indexAction()&lt;br /&gt;   {&lt;br /&gt;       $users  = new Users();&lt;br /&gt;       $data  = $users-&amp;gt;fetchAll($users-&amp;gt;select());&lt;br /&gt;       $this-&amp;gt;view-&amp;gt;data = $data-&amp;gt;toArray();&lt;br /&gt;   }&lt;br /&gt;  &lt;br /&gt;   public function addAction()&lt;br /&gt;   {&lt;br /&gt;       $users  = new Users();&lt;br /&gt;       $form = new CustomForm();&lt;br /&gt;       $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;       if ($this-&amp;gt;getRequest()-&amp;gt;isPost()) {&lt;br /&gt;       $formData  = $this-&amp;gt;_request-&amp;gt;getPost();&lt;br /&gt;           if ($form-&amp;gt;isValid($formData)) {&lt;br /&gt;               if ($formData['password'] != $formData['password2']) {&lt;br /&gt;                   $this-&amp;gt;view-&amp;gt;errorMsg = "Password and Confirm Password must match.";&lt;br /&gt;                   $this-&amp;gt;render('add');&lt;br /&gt;                   return;&lt;br /&gt;           }&lt;br /&gt;           unset($formData['password2']);&lt;br /&gt;           unset($formData['register']);&lt;br /&gt;           $users-&amp;gt;insert($formData);&lt;br /&gt;               }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The code in addAction create form, get posted data, check whether password and confirm password match and then insert data in the users table.&lt;br /&gt;&lt;br /&gt;Now create add.phtml in html_root/application/views/scripts/index/ and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Add User&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;   if ($this-&amp;gt;errorMsg) {&lt;br /&gt;   echo $this-&amp;gt;errorMsg;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;   // for displaying form&lt;br /&gt;   echo $this-&amp;gt;form;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Next we are going to create action for editing the users table data. Write the following code in the your IndexController.php&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class IndexController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;   public function indexAction()&lt;br /&gt;   {&lt;br /&gt;       //$this-&amp;gt;_helper-&amp;gt;layout-&amp;gt;disableLayout();&lt;br /&gt;       $users  = new Users();&lt;br /&gt;       $data  = $users-&amp;gt;fetchAll($users-&amp;gt;select());&lt;br /&gt;       $this-&amp;gt;view-&amp;gt;data = $data-&amp;gt;toArray();&lt;br /&gt;   }&lt;br /&gt;  &lt;br /&gt;   public function addAction()&lt;br /&gt;   {&lt;br /&gt;       $users  = new Users();&lt;br /&gt;       $form = new CustomForm();&lt;br /&gt;       $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;  &lt;br /&gt;&lt;br /&gt;       if ($this-&amp;gt;getRequest()-&amp;gt;isPost()) {&lt;br /&gt;       $formData  = $this-&amp;gt;_request-&amp;gt;getPost();&lt;br /&gt;           if ($form-&amp;gt;isValid($formData)) {&lt;br /&gt;               if ($formData['password'] != $formData['password2']) {&lt;br /&gt;                   $this-&amp;gt;view-&amp;gt;errorMsg = "Password and Confirm Password must match.";&lt;br /&gt;                   $this-&amp;gt;render('add');&lt;br /&gt;                   return;&lt;br /&gt;               }&lt;br /&gt;           unset($formData['password2']);&lt;br /&gt;           unset($formData['register']);&lt;br /&gt;           $users-&amp;gt;insert($formData);&lt;br /&gt;           }&lt;br /&gt;       }&lt;br /&gt;   }&lt;br /&gt;  &lt;br /&gt;   public function editAction()&lt;br /&gt;   {&lt;br /&gt;       $users  = new Users();&lt;br /&gt;       $form = new CustomForm();&lt;br /&gt;      &lt;br /&gt;       $id = $this-&amp;gt;_getParam("id",1);&lt;br /&gt;       $select = $users-&amp;gt;select()&lt;br /&gt;               -&amp;gt;where("id = ?",$id);&lt;br /&gt;       $data = $users-&amp;gt;fetchRow($select);&lt;br /&gt;       $form-&amp;gt;populate($data-&amp;gt;toArray());&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;       if ($this-&amp;gt;getRequest()-&amp;gt;isPost()) {&lt;br /&gt;       $formData  = $this-&amp;gt;_request-&amp;gt;getPost();&lt;br /&gt;           if ($form-&amp;gt;isValid($formData)) {&lt;br /&gt;               if ($formData['password'] != $formData['password2']) {&lt;br /&gt;                   $this-&amp;gt;view-&amp;gt;errorMsg = "Password and Confirm Password must match.";&lt;br /&gt;                   $this-&amp;gt;render('add');&lt;br /&gt;                   return;&lt;br /&gt;               }&lt;br /&gt;           unset($formData['password2']);&lt;br /&gt;           unset($formData['register']);&lt;br /&gt;           $users-&amp;gt;update($formData,"id = $id");&lt;br /&gt;               }&lt;br /&gt;       }&lt;br /&gt;       $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;   }&lt;br /&gt;  &lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The above code fetch the data and populate the form, and then get the posted data and update the users table based on the id.&lt;br /&gt;&lt;br /&gt;Create edit.phtml in html_root/application/views/scripts/index/ and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Edit User&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;   if ($this-&amp;gt;errorMsg) {&lt;br /&gt;   echo $this-&amp;gt;errorMsg;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;   // for displaying form&lt;br /&gt;   echo $this-&amp;gt;form;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;6. Create authentication application&lt;br /&gt;As now we have created database application successfully, we are going to create authentication application.&lt;br /&gt;&lt;br /&gt;(i). Creating login form&lt;br /&gt;in your html_root/application/forms/ create LoginForm.php and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class LoginForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;   public function init()&lt;br /&gt;   {&lt;br /&gt;       $this-&amp;gt;setName('login');&lt;br /&gt;       $this-&amp;gt;setMethod('post');&lt;br /&gt;      &lt;br /&gt;       $userName =  $this-&amp;gt;createElement('text', 'userName',array('label' =&amp;gt; 'username'  ));&lt;br /&gt;       $userName-&amp;gt;addFilters(array('StringTrim'))&lt;br /&gt;           -&amp;gt;addValidator('StringLength', false,array(5,50))&lt;br /&gt;           -&amp;gt;setValue('')&lt;br /&gt;           -&amp;gt;setRequired(true);&lt;br /&gt;&lt;br /&gt;       $password =  $this-&amp;gt;createElement('password','password',array('label' =&amp;gt; 'password'  ));&lt;br /&gt;       $password -&amp;gt;setRequired(true)&lt;br /&gt;           -&amp;gt;addValidator('StringLength', false,array(5,50))&lt;br /&gt;           -&amp;gt;setValue('');&lt;br /&gt;          &lt;br /&gt;       $submit =  $this-&amp;gt;createElement('submit','save',array('label' =&amp;gt; 'login'));&lt;br /&gt;       $submit-&amp;gt;setRequired(false)&lt;br /&gt;           -&amp;gt;setIgnore(true);&lt;br /&gt;          &lt;br /&gt;       $this-&amp;gt;addElements(array(&lt;br /&gt;                   $userName,&lt;br /&gt;                   $password,&lt;br /&gt;                   $submit,&lt;br /&gt;                   ));&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the above form we add two elements, a text box for entering username and password field for entering user password. We also add submit input box.&lt;br /&gt;(ii).Next we create AuthController.php in html_root/application/controllers/ and write the following code&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class AuthController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;   public function loginAction()&lt;br /&gt;   {&lt;br /&gt;       $form = new LoginForm();&lt;br /&gt;       if ($this-&amp;gt;getRequest()-&amp;gt;isPost()) {&lt;br /&gt;       $values = $this-&amp;gt;_request-&amp;gt;getPost();&lt;br /&gt;           if ($form-&amp;gt;isValid($values)) {&lt;br /&gt;               $users  = new Users();&lt;br /&gt;               $auth = Zend_Auth::getInstance();&lt;br /&gt;               $authAdapter = new Zend_Auth_Adapter_DbTable($users-&amp;gt;getAdapter());&lt;br /&gt;       $authAdapter-&amp;gt;setTableName('users');&lt;br /&gt;               $authAdapter-&amp;gt;setIdentityColumn('userName');&lt;br /&gt;               $authAdapter-&amp;gt;setCredentialColumn('password');&lt;br /&gt;              &lt;br /&gt;               $authAdapter-&amp;gt;setIdentity($values['userName']);&lt;br /&gt;               $authAdapter-&amp;gt;setCredential($values['password']);&lt;br /&gt;       try {&lt;br /&gt;                    $result = $auth-&amp;gt;authenticate($authAdapter);&lt;br /&gt;       } catch (Zend_Exception $e) {&lt;br /&gt;                    $this-&amp;gt;view-&amp;gt;errorMsg = $e-&amp;gt;getMessage() . "&amp;lt;br&amp;gt;";&lt;br /&gt;               }&lt;br /&gt;              &lt;br /&gt;           if ($result-&amp;gt;isValid()) {&lt;br /&gt;               $data = $authAdapter-&amp;gt;getResultRowObject();&lt;br /&gt;               $sess = new Zend_Session_Namespace();&lt;br /&gt;               $sess-&amp;gt;username = $data-&amp;gt;useruame;&lt;br /&gt;               echo "Welcome &amp;lt;b&amp;gt;".$data-&amp;gt;username.'&amp;lt;/b&amp;gt;&amp;lt;br&amp;gt;You successfully logged in.';&lt;br /&gt;} else {&lt;br /&gt;   echo "invalid username or password try again.";&lt;br /&gt;}&lt;br /&gt;       }&lt;br /&gt;       }&lt;br /&gt;       $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In login action we initialize our login form, check for submitted data. We then instantiate our user model as well as Zend_Auth. Setting table name, identity column and credential column. We then pass values submitted through form to identity column and credential column. After setting these things we call authenticate() method.&lt;br /&gt;This authenticate column perform authentication for us.&lt;br /&gt;We then call isValid() method that return true or false based on the authentication.&lt;br /&gt;If isValid() return true, we get the user specific information by calling getResultRowObject() method.&lt;br /&gt;We then create session and assign username to it.&lt;br /&gt;The last thing we will need to create is view template against login action. In html_root/application/views/scripts create auth/login.phtml and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; border: 1px dashed rgb(153, 153, 153); line-height: 14px; padding: 5px; overflow: auto; width: 100%;"&gt;&lt;code&gt;&amp;lt;fieldset style="width:400px"&amp;gt;&lt;br /&gt;&amp;lt;legend&amp;gt;Login&amp;lt;/legend&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;echo $this-&amp;gt;form;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;div&amp;gt;&amp;lt;a href="../index/add" style="color:blue"&amp;gt;New user Sign up here&amp;lt;/a&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;/fieldset&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;That’s it. Our login authentication. For registration, you can use add form I have previously created.&lt;br /&gt;I think its enough for now. I will discuss other things later on hopefully.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-8206352427089435209?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/8206352427089435209/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-building-complete.html#comment-form' title='26 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8206352427089435209'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8206352427089435209'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-building-complete.html' title='Zend Framework building complete application'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_bn44g8iuZbQ/Sk8z9pxDNNI/AAAAAAAAAC4/jmo5rt-lYN8/s72-c/zend_mvc_directory_structure.JPG' height='72' width='72'/><thr:total>26</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-904322671168120550</id><published>2009-07-03T11:52:00.000-07:00</published><updated>2009-07-03T12:01:30.237-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Creating a nice Dojo Form in Zend Framework</title><content type='html'>Well, after writing few separate article about Zend Framework and dojo, I feel that I’d need to write a complete Zend_Dojo_Form. So here I am with complete example.&lt;br /&gt;I am going to explain everything step by step.&lt;br /&gt;1. Download Zend Framework latest version&lt;br /&gt;Download least stable version from http://www.zend.com. Copy external/dojo to js/.&lt;br /&gt;Hopefully you will create your directory structure as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;html_root&lt;br /&gt;    /application&lt;br /&gt;        /controllers&lt;br /&gt;            DojoController.php&lt;br /&gt;        /models&lt;br /&gt;        /forms&lt;br /&gt;            CustomDojoForm.php&lt;br /&gt;        /views&lt;br /&gt;            /scripts&lt;br /&gt;                /dojo&lt;br /&gt;                    index.phtml&lt;br /&gt;    /libaray&lt;br /&gt;        /Zend&lt;br /&gt;    /public&lt;br /&gt;        /js&lt;br /&gt;            /dojo&lt;br /&gt;        /css&lt;br /&gt;        /images&lt;br /&gt;        /bootstrap.php&lt;br /&gt;    /index.phtm&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;It’s not compulsory to create the similar directory structure I have created, this can vary. For best practice read Zend Quick start from Zend Framework documentation.&lt;br /&gt;&lt;br /&gt;2. Enable dojo in the bootstrap file&lt;br /&gt;&lt;br /&gt;I am not going to discuss everything you will need to have in your bootstrap file. I am explaining only the line of code needed to enable dojo.&lt;br /&gt;You may have initialized your view in the bootstrap file as&lt;br /&gt;$view = new Zend_View();&lt;br /&gt;if you haven’t, you will need to write the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$view = new Zend_View(); &lt;br /&gt;$view-&amp;gt;addHelperPath('Zend/Dojo/View/Helper/', 'Zend_Dojo_View_Helper'); &lt;br /&gt;$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer(); &lt;br /&gt;$viewRenderer-&amp;gt;setView($view); &lt;br /&gt;Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;If you already have&lt;br /&gt;$view = new Zend_View(); &lt;br /&gt;in your bootstrap, no need to initialize it twice.&lt;br /&gt;The second line is compulsory. It add helper path. This means that your view now can access all the helpers in library/Zend/Dojo/View/Helper/ directory.&lt;br /&gt;In the next lines, I initialize viewRenderer, add view to it, and add viewRenderer to HelperBroker.&lt;br /&gt;That’s it. We have now made all necessary changes in our bootstrap file.&lt;br /&gt;3. Making necessary changes in your layout file.&lt;br /&gt;Well, if are newbie. You will need to understand two step view before making the following changes. Read my article http://zendguru.wordpress.com/&lt;br /&gt;The changes we will need in our layout file are&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;$this-&amp;gt;dojo()-&amp;gt;setDjConfigOption('usePlainJson',true)&lt;br /&gt;        -&amp;gt;addStylesheetModule('dijit.themes.tundra')&lt;br /&gt;        -&amp;gt;setLocalPath(&amp;quot;http://localhost/zend/public/js/dojo/dojo/dojo.js&amp;quot;);&lt;br /&gt;    &lt;br /&gt;echo $this-&amp;gt;dojo();&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body class=&amp;quot;tundra&amp;quot;&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Nothing hard to understand here. In the first line we set dojo configuration option. In the second line we add style sheet module, and the third line we add path to our dojo.js file.&lt;br /&gt;After setting these option, we call dojo() helper method as&lt;br /&gt;echo $this-&gt;dojo();&lt;br /&gt;&lt;br /&gt;We have now made the entire necessary configuration in our bootstrap and layout file. It’s now time to play with Zend_Dojo_Form.&lt;br /&gt;4. Creating Zend_Dojo_Form&lt;br /&gt;Creating a dojo form as simple as this.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?&lt;br /&gt;class DojoForm extends Zend_Dojo_Form&lt;br /&gt;{&lt;br /&gt;    public $_selectOptions;&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;_selectOptions=array(&lt;br /&gt;                '1' =&amp;gt; 'red',&lt;br /&gt;                '2' =&amp;gt; 'blue',&lt;br /&gt;                '3' =&amp;gt; 'gray'&lt;br /&gt;            );&lt;br /&gt;            &lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;        $this-&amp;gt;setAttribs(array(&lt;br /&gt;                'name' =&amp;gt; 'masterform'&lt;br /&gt;            ));&lt;br /&gt;        $this-&amp;gt;setDecorators(array(&lt;br /&gt;                'FormElements',&lt;br /&gt;                array(&lt;br /&gt;                    'TabContainer',&lt;br /&gt;                     array(&lt;br /&gt;                        'id' =&amp;gt; 'tabContainer',&lt;br /&gt;                        'style' =&amp;gt; 'width:660px; height:500px',&lt;br /&gt;                        'dijitParams' =&amp;gt; array(&lt;br /&gt;                            'tabPosition' =&amp;gt; 'top',&lt;br /&gt;                        )&lt;br /&gt;                    ),&lt;br /&gt;                    'DijitForm'&lt;br /&gt;                )&lt;br /&gt;            )); &lt;br /&gt;        &lt;br /&gt;        $textForm= new Zend_Dojo_Form_SubForm();&lt;br /&gt;        $textForm-&amp;gt;setAttribs(array(&lt;br /&gt;                'name'=&amp;gt; 'textboxtab',&lt;br /&gt;                'legend' =&amp;gt; 'Text Elements',&lt;br /&gt;                'dijitParams' =&amp;gt; array(&lt;br /&gt;                    'title' =&amp;gt; 'Text Elements',&lt;br /&gt;                )&lt;br /&gt;        ));&lt;br /&gt;        $textForm-&amp;gt;addElement(&lt;br /&gt;                'TextBox',&lt;br /&gt;                'textbox',&lt;br /&gt;                array(&lt;br /&gt;                    'value' =&amp;gt; 'some text',&lt;br /&gt;                    'label' =&amp;gt; 'TextBox',&lt;br /&gt;                    'trim' =&amp;gt; true,&lt;br /&gt;                    'propercase' =&amp;gt; true,&lt;br /&gt;                )&lt;br /&gt;            );&lt;br /&gt;        $textForm-&amp;gt;addElement(&lt;br /&gt;                'DateTextBox',&lt;br /&gt;                'datebox',&lt;br /&gt;                array(&lt;br /&gt;                    'value' =&amp;gt; '2008-07-05',&lt;br /&gt;'label' =&amp;gt; 'DateTexBox',&lt;br /&gt;                    'required' =&amp;gt; true,&lt;br /&gt;                )&lt;br /&gt;            );&lt;br /&gt;        $textForm-&amp;gt;addElement(&lt;br /&gt;                'TimeTextBox',&lt;br /&gt;                'timebox',&lt;br /&gt;                array(&lt;br /&gt;                    'label' =&amp;gt; 'TimeTexBox',&lt;br /&gt;                    'required' =&amp;gt; true,&lt;br /&gt;                )&lt;br /&gt;            );&lt;br /&gt;        $textForm-&amp;gt;addElement(&lt;br /&gt;                'CurrencyTextBox',&lt;br /&gt;                'currencybox',&lt;br /&gt;                array(&lt;br /&gt;                    'label' =&amp;gt; 'CurrencyTexBox',&lt;br /&gt;                    'required' =&amp;gt; true,&lt;br /&gt;                    'currency'=&amp;gt;'USD',&lt;br /&gt;                    'invalidMessage' =&amp;gt; 'Invalid amount',&lt;br /&gt;                    'symbol' =&amp;gt; 'USD',&lt;br /&gt;                    'type' =&amp;gt; 'currency',&lt;br /&gt;                )&lt;br /&gt;            );&lt;br /&gt;        $textForm-&amp;gt;addElement(&lt;br /&gt;                'NumberTextBox',&lt;br /&gt;                'numberbox',&lt;br /&gt;                array(&lt;br /&gt;                    'label' =&amp;gt; 'NumberTexBox',&lt;br /&gt;                    'required' =&amp;gt; true,&lt;br /&gt;                    'invalidMessage'=&amp;gt;'Invalid elevation.',&lt;br /&gt;                    'constraints' =&amp;gt; array(&lt;br /&gt;                        'min' =&amp;gt; -2000,&lt;br /&gt;                        'max'=&amp;gt; 2000,&lt;br /&gt;                        'places' =&amp;gt; 0,&lt;br /&gt;                    )&lt;br /&gt;                )&lt;br /&gt;            );&lt;br /&gt;        $textForm-&amp;gt;addElement(&lt;br /&gt;                'ValidationTextBox',&lt;br /&gt;                'validationbox',&lt;br /&gt;                array(&lt;br /&gt;                    'label' =&amp;gt; 'ValidationTexBox',&lt;br /&gt;                    'required' =&amp;gt; true,&lt;br /&gt;                    'regExp' =&amp;gt; '[\w]+',&lt;br /&gt;                    'invalidMessage' =&amp;gt; 'invalid non-space text.',&lt;br /&gt;                )&lt;br /&gt;            );&lt;br /&gt;        $textForm-&amp;gt;addElement(&lt;br /&gt;                'Textarea',&lt;br /&gt;                'textarea',&lt;br /&gt;                array(&lt;br /&gt;                    'label' =&amp;gt; 'TextArea',&lt;br /&gt;                    'required' =&amp;gt; true,&lt;br /&gt;                    'style' =&amp;gt; 'width:200px',&lt;br /&gt;                )&lt;br /&gt;            );&lt;br /&gt;            &lt;br /&gt;        $toggleForm= new Zend_Dojo_Form_SubForm();&lt;br /&gt;        $toggleForm-&amp;gt;setAttribs(array(&lt;br /&gt;                    'name' =&amp;gt; 'toggletab',&lt;br /&gt;                    'legend' =&amp;gt; 'Toggle Elements',&lt;br /&gt;                ));&lt;br /&gt;        $toggleForm-&amp;gt;addElement(&lt;br /&gt;                'NumberSpinner',&lt;br /&gt;                'ns',&lt;br /&gt;                array(&lt;br /&gt;                    'value' =&amp;gt; '7',&lt;br /&gt;                    'label' =&amp;gt; 'NumberSpinner',&lt;br /&gt;                    'smallDelta' =&amp;gt; 5,&lt;br /&gt;                    'largeDelta' =&amp;gt; 25,&lt;br /&gt;                    'defaultTimeout' =&amp;gt; 1000,&lt;br /&gt;                    'timeoutChangeRate' =&amp;gt; 100,&lt;br /&gt;                    'min' =&amp;gt; 9,&lt;br /&gt;                    'max' =&amp;gt; 1550,&lt;br /&gt;                    'places' =&amp;gt; 0,&lt;br /&gt;                    'maxlength' =&amp;gt; 20,&lt;br /&gt;                )&lt;br /&gt;            );&lt;br /&gt;        $toggleForm-&amp;gt;addElement(&lt;br /&gt;            'Button',&lt;br /&gt;            'dijitButton',&lt;br /&gt;            array(&lt;br /&gt;                'label' =&amp;gt; 'Button',&lt;br /&gt;            )&lt;br /&gt;        );&lt;br /&gt;        $toggleForm-&amp;gt;addElement(&lt;br /&gt;            'CheckBox',&lt;br /&gt;            'checkbox',&lt;br /&gt;            array(&lt;br /&gt;                'label' =&amp;gt; 'CheckBox',&lt;br /&gt;                'checkedValue' =&amp;gt; 'foo',&lt;br /&gt;                'uncheckedValue' =&amp;gt; 'bar',&lt;br /&gt;                'checked' =&amp;gt; true,&lt;br /&gt;            )&lt;br /&gt;        );&lt;br /&gt;        $selectForm= new Zend_Dojo_Form_SubForm();&lt;br /&gt;        $selectForm-&amp;gt;setAttribs(array(&lt;br /&gt;                    'name' =&amp;gt; 'selecttab',&lt;br /&gt;                    'legend' =&amp;gt; 'Select Elements',&lt;br /&gt;                ));&lt;br /&gt;        $selectForm-&amp;gt;addElement(&lt;br /&gt;            'ComboBox',&lt;br /&gt;            'comboboxselect',&lt;br /&gt;            array(&lt;br /&gt;                'label' =&amp;gt; 'ComboBox(select)',&lt;br /&gt;                'value' =&amp;gt; 'blue',&lt;br /&gt;                'autocomplete'=&amp;gt;false,&lt;br /&gt;                'multiOptions' =&amp;gt; $this-&amp;gt;_selectOptions,&lt;br /&gt;            )&lt;br /&gt;        );&lt;br /&gt;        $selectForm-&amp;gt;addElement(&lt;br /&gt;            'FilteringSelect',&lt;br /&gt;            'filterselect',&lt;br /&gt;            array(&lt;br /&gt;                'label' =&amp;gt; 'FilteringSelect(select)',&lt;br /&gt;                'value' =&amp;gt; 'blue',&lt;br /&gt;                'autocomplete'=&amp;gt;false,&lt;br /&gt;                'multiOptions' =&amp;gt; $this-&amp;gt;_selectOptions,&lt;br /&gt;            )&lt;br /&gt;        );&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;addSubForm($textForm,'textForm')&lt;br /&gt;                -&amp;gt;addSubForm($toggleForm,'toggleForm')&lt;br /&gt;                -&amp;gt;addSubForm($selectForm,'selectForm');&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;I don’t think I can explain everything in the form. Just giving you a clue.&lt;br /&gt;I’ve created three sub forms, a text form contain elements such as textbox, date textbox, time textbox etc, a toggle sub form contain elements like number spinner, button and checkbox, and a select sub form containing select box and filtering select. I also have set different attributes for these elements.&lt;br /&gt;&lt;br /&gt;3. Instantiating Zend_Dojo_Form in your controller&lt;br /&gt;Your DojoController must have the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class DojoController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;    function indexAction()&lt;br /&gt;    {&lt;br /&gt;        $form= new DojoForm();&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;form= $form;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;I don’t think anything needs to be explained.&lt;br /&gt;&lt;br /&gt;4. Displaying form in template&lt;br /&gt;Your template in views/scripts/dojo/ called index.phtml must have the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;    echo $this-&amp;gt;form; &lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-904322671168120550?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/904322671168120550/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-nice-dojo-form-in-zend.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/904322671168120550'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/904322671168120550'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-nice-dojo-form-in-zend.html' title='Creating a nice Dojo Form in Zend Framework'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-6246123044619930422</id><published>2009-07-02T10:10:00.000-07:00</published><updated>2009-07-08T22:46:51.181-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Create Dojo grid in Zend Framework- a nice example</title><content type='html'>About a month or two earlier when I used dojo calendar in my application and write article about the Zend Framework and dojo I was wondering why zend make collaboration with zend. But today when I created a grid using zend dojo I feel the real power of the dojo in Zend framework. In this article I am going to give a simple example and create a grid using Zend framework and dojo.&lt;br /&gt;&lt;br /&gt;At the end of this tutorial we will have a grid like the following&lt;br /&gt;&lt;a href="http://4.bp.blogspot.com/_bn44g8iuZbQ/SkzqpNehFpI/AAAAAAAAACw/hNHv97FRaz4/s1600-h/dojo_grid_example1.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 144px;" src="http://4.bp.blogspot.com/_bn44g8iuZbQ/SkzqpNehFpI/AAAAAAAAACw/hNHv97FRaz4/s320/dojo_grid_example1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5353912050749871762" /&gt;&lt;/a&gt;&lt;br /&gt;So let’s feel the power of dojo in zend.&lt;br /&gt;First execute the following query for creating a table.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;CREATE TABLE 'jobs' (&lt;br /&gt;    'id' int(11) NOT NULL auto_increment,&lt;br /&gt;    'title' varchar(50) NOT NULL,&lt;br /&gt;    'description' text,&lt;br /&gt;    'posted_date' datetime default NULL,&lt;br /&gt;    PRIMARY KEY  ('id')&lt;br /&gt;)&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This will create a table in your database.&lt;br /&gt;&lt;br /&gt;Create a model in your models directory and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class Jobs extends Zend_Db_Table_Abstract&lt;br /&gt;{&lt;br /&gt;    protected $_name='jobs';&lt;br /&gt;    public function getJobsData()&lt;br /&gt;    {&lt;br /&gt;        $select = $this-&amp;gt;_db-&amp;gt;select()&lt;br /&gt;                        -&amp;gt;from($this-&amp;gt;_name);&lt;br /&gt;        $results = $this-&amp;gt;getAdapter()-&amp;gt;fetchAll($select);&lt;br /&gt;        return $results;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt; and save this table as Jobs.php&lt;br /&gt;&lt;br /&gt;In the code above, we first extend our model from Zend_Db_Table_Abstract, define its name and define our custom function getJobsData() that fetch all the rows in the jobs table. We return the results as an array.&lt;br /&gt;&lt;br /&gt;Next create a controller JobsController in you controller’s directory and place the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class JobsController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;    public function  viewAction()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public function  recordsAction()&lt;br /&gt;    {&lt;br /&gt;        $jobs = new Jobs();&lt;br /&gt;        $data= $jobs-&amp;gt;getJobsData();&lt;br /&gt;        $dojoData= new Zend_Dojo_Data(&amp;#8217;id&amp;#8217;,$data,&amp;#8217;id&amp;#8217;);&lt;br /&gt;        echo $dojoData-&amp;gt;toJson();&lt;br /&gt;        exit;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the above code we create two action view and records. We have placed nothing in the view action. In the recordsAction, we create an instance of Jobs model class.and then call its getJobsData() method which will give us an array of records. Next we create an instance of Zend_Dojo_Data() and give the fetched data to it. And finally we echo the data converted it into the Json.&lt;br /&gt;&lt;br /&gt;We don’t need to create a view for the records action because we have placed exit it the end of this action which will stop rendering of the view. As we will call this action form our grid view template page so no need to define phtml file for it.&lt;br /&gt;&lt;br /&gt;However we will need to create template file for our viewAction. In scripts/views/ directory create view.phtml file and place the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Dojo_View_Helper_Dojo::setUseDeclarative();&lt;br /&gt;$this-&amp;gt;dojo()-&amp;gt;setLocalPath('http://localhost/Zend/js/dojo/dojo/dojo.js')&lt;br /&gt;            -&amp;gt;addStyleSheetModule(&amp;#8217;dijit.themes.tundra&amp;#8217;)&lt;br /&gt;            -&amp;gt;addStylesheet('http://localhost/Zend/js/dojo/dojox/grid/_grid/tundraGrid.css');&lt;br /&gt;echo $this-&amp;gt;dojo();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;    dojo.require(&amp;quot;dojox.data.QueryReadStore&amp;quot;);&lt;br /&gt;    dojo.require(&amp;quot;dojox.grid.Grid&amp;quot;);&lt;br /&gt;    dojo.require(&amp;quot;dojo.parser&amp;quot;);&lt;br /&gt;&amp;lt;/script&amp;gt;             &lt;br /&gt;&amp;lt;body class=&amp;quot;tundra&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;div dojoType=&amp;quot;dojox.data.QueryReadStore&amp;quot; jsId=&amp;quot;activeStore&amp;quot;, url=&amp;quot;records&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;    &amp;lt;div dojoType=&amp;quot;dojox.grid.data.DojoData&amp;quot; jsId=&amp;quot;model&amp;quot; rowsPerPage=&amp;quot;20&amp;#8243; store=&amp;quot;activeStore&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;    &amp;lt;table id=&amp;quot;activePastes&amp;quot; dojoType=&amp;quot;dojox.grid.Grid&amp;quot; model=&amp;quot;model&amp;quot; style=&amp;quot;height:300px; width:700px;&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;thead&amp;gt;&lt;br /&gt;            &amp;lt;tr&amp;gt;&lt;br /&gt;                &amp;lt;th field=&amp;quot;id&amp;quot;&amp;gt;Id&amp;lt;/th&amp;gt;&lt;br /&gt;                &amp;lt;th field=&amp;quot;title&amp;quot;&amp;gt;Title&amp;lt;/th&amp;gt;&lt;br /&gt;                &amp;lt;th field=&amp;quot;description&amp;quot;&amp;gt;Description&amp;lt;/th&amp;gt;&lt;br /&gt;                &amp;lt;th field=&amp;quot;posted_date&amp;quot;&amp;gt;Posted&amp;lt;/th&amp;gt;&lt;br /&gt;            &amp;lt;/tr&amp;gt;&lt;br /&gt;        &amp;lt;/thead&amp;gt;&lt;br /&gt;    &amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Keep in mind this is the main template file where we are creating our gird.&lt;br /&gt;&lt;br /&gt;In the first statement I told zend to use declarative instead of programmatic behavior which is default. Next I set local path and add specific stylesheets. Then in the javascript code I used statement&lt;br /&gt;&lt;br /&gt;Dojo.requre(’dojox.data.’) etc&lt;br /&gt;&lt;br /&gt;To include specific dojo js modules.&lt;br /&gt;&lt;br /&gt;In the body tag I specify a class “tundra”. This is important for the stylesheet I have added.&lt;br /&gt;&lt;br /&gt;Next tow div’s and table are  the main code for creating grid.&lt;br /&gt;&lt;br /&gt;The first div fetch the records from the url specified. This url may be different if you fetch records form the other controller or source. Please specify valid url otherwise you will not get what you want.&lt;br /&gt;&lt;br /&gt;The next div act as a bridge between our first div and the table. This div take data from the first div and give it to the table for display purposes.&lt;br /&gt;&lt;br /&gt;Keep in mind that all the attributes of the div’s and table are compulsory. Removing any of the attribute may result in unvalid records or empty page. So define everything that I have defined. Once you become able to display your records, you can play with these attributes.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-6246123044619930422?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/6246123044619930422/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/create-dojo-grid-in-zend-framework-nice.html#comment-form' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6246123044619930422'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6246123044619930422'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/create-dojo-grid-in-zend-framework-nice.html' title='Create Dojo grid in Zend Framework- a nice example'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_bn44g8iuZbQ/SkzqpNehFpI/AAAAAAAAACw/hNHv97FRaz4/s72-c/dojo_grid_example1.jpg' height='72' width='72'/><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-5667077843083778225</id><published>2009-07-02T09:43:00.000-07:00</published><updated>2009-07-02T10:08:28.735-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Framework: Storing session data in database</title><content type='html'>In one of my previous post I wrote how to save session data in the database. The reason behind saving session data in database is that data become more secure and can be easily retrieved later on.&lt;br /&gt;Let’s look how simple and easy it is to save session data in database using Zend_Session_SaveHandler_DbTable in Zend Framework.&lt;br /&gt;1. Creating database table for holding session data&lt;br /&gt;Before writing code you will need to create a table in the database for holding session data. Execute the following query for this purpose.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;CREATE TABLE `session` (&lt;br /&gt;`id` char(32),&lt;br /&gt;`modified` int,&lt;br /&gt;`lifetime` int,&lt;br /&gt;`data` text,&lt;br /&gt;PRIMARY KEY (`id`)&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;2.Making necessary configuration in your bootstrap file.&lt;br /&gt;You will only need only few lines of code in your bootstrap file.&lt;br /&gt;After making database configuration in your bootstrap file, write the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$config = array(&lt;br /&gt;    'name' =&amp;gt; 'session',&lt;br /&gt;    'primary' =&amp;gt; 'id',&lt;br /&gt;    'modifiedColumn' =&amp;gt; 'modified',&lt;br /&gt;    'dataColumn' =&amp;gt; 'data',&lt;br /&gt;    'lifetimeColumn' =&amp;gt; 'lifetime'&lt;br /&gt;);&lt;br /&gt;&lt;br /&gt;Zend_Session::setSaveHandler(new&lt;br /&gt;                Zend_Session_SaveHandler_DbTable($config));&lt;br /&gt;Zend_Session::start();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the $config array we tell the name of the table that will store the session information, primary key of the table, column that will store the session modification timestamp(*nix timestamp), column that will store the session data, and the column that save the information about how long the session will last.&lt;br /&gt;&lt;br /&gt;After defining this configuration array we call setSaveHandler() method- static method, of the Zend_Session. This setSaveHandler() method accept Zend_Session_SaveHandler_DbTable object. Zend_Session_SaveHandler_DbTable take configuration array as an argument.&lt;br /&gt;&lt;br /&gt;We have now done all the necessary configuration. The only thing we will need to do now is to start our session. Session can be started in the bootstrap file, however it’s not necessary for the session to be started here. You can start it in any controller you needed.&lt;br /&gt;&lt;br /&gt;Anywhere in your controller, write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$namespace = new Zend_Session_Namespace();&lt;br /&gt;$namespace-&amp;gt;name = &amp;quot;faheem&amp;quot;;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;and check your session table. The table will not only hold session id, but also the modified timestamp of when session was modified, life time of the session and the session data in special format.&lt;br /&gt;Try it. Its really cool.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-5667077843083778225?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/5667077843083778225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-storing-session-data-in.html#comment-form' title='9 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/5667077843083778225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/5667077843083778225'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-storing-session-data-in.html' title='Zend Framework: Storing session data in database'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>9</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-5327538755201564393</id><published>2009-07-02T09:15:00.000-07:00</published><updated>2009-07-02T09:27:04.708-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Php'/><title type='text'>PHP: Storing session data in database</title><content type='html'>Session data by default is stored in /tmp directory on the server in the form of text files. It wouldn’t be a good practice to store session information in the default directory because users can easily get these information. You must either change the directory, or the best practice is to store the information the database. Storing session data in the database not only increase your application security, but also provide you an ability to fetch session related information easily from the database.&lt;br /&gt;PHP provide very easy mechanism and functions for storing session information in the database.&lt;br /&gt;In order to store information in the database you will need to have a table containing fields such sessionId for storing unique session Id, sessionData for storing session data and accessDate that store date when session was last accessed.&lt;br /&gt;Once table is successfully created, saving session requires only two steps.&lt;br /&gt;1. Creating function that interact with and store data in the database.&lt;br /&gt;2. Tell PHP to use the functions defined by using session_set_atuo_save() method.&lt;br /&gt;Now let’s discuss these two steps&lt;br /&gt;1. Creating functions for interacting with database&lt;br /&gt;Before using session_set_auto_save() method, we will need to define six method. These method will then be passed as argument to the session_set_auto_save() method. These six methods are each called on the even taken place. Events are fired when session is started, session is closed, session data is read, session data is written, session data is destroyed, and the six argument/function is used for garbage collection. Garbage collection is used to free resources etc.&lt;br /&gt;Now let’s define and discuss functions for each of these events.&lt;br /&gt;(i) Defining a function which will be called when session is started.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$dbConn = null;&lt;br /&gt;&lt;br /&gt;function open_session()&lt;br /&gt;{&lt;br /&gt;    global $dbConn;&lt;br /&gt;    $dbConn = mysqli_connect('host','username','password','dbname') or die('cannot connect to the database');&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This method is called each time session is started. The function contains code for connecting to the database only. You can place whatever you wish.&lt;br /&gt;(ii) Defining function called when session is closed&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;function close_session()&lt;br /&gt;{&lt;br /&gt;    global $dbConn;&lt;br /&gt;    $dbConn = mysqli_close();&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;(iii) Defining function called when session  is read&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;function read_session($sid)&lt;br /&gt;{&lt;br /&gt;    global $dbConn;&lt;br /&gt;&lt;br /&gt;    $q = sprintf('SELECT data FROM sessions WHERE id=&amp;quot;%s&amp;quot;', mysqli_real_escape_string($dbConn, $sid));&lt;br /&gt;    &lt;br /&gt;    $r = mysqli_query($dbConn, $q);&lt;br /&gt;    if (mysqli_num_rows($r) == 1) {&lt;br /&gt;         list($data) = mysqli_fetch_array($r, MYSQLI_NUM);&lt;br /&gt;    return $data;&lt;br /&gt;    } else { &lt;br /&gt;        return '';&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This function take current sessionId as argument and read the data from the database.&lt;br /&gt;(iv) Defining function called when session data is written&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;function write_session($sid, $data)&lt;br /&gt;{&lt;br /&gt;    global $dbConn;&lt;br /&gt;&lt;br /&gt;    $q = sprintf('REPLACE INTO sessions (id, data) VALUES (&amp;quot;%s&amp;quot;, &amp;quot;%s&amp;quot;)',&lt;br /&gt;            mysqli_real_escape_string($dbConn, $sid), mysqli_real_escape_string($dbConn,&lt;br /&gt;                                                                                    $data));&lt;br /&gt;    $r = mysqli_query($dbConn, $q);&lt;br /&gt;    return mysqli_affected_rows($dbConn);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This function takes two argument sessions current Id and the data to be written. The code written here inserts session id and data into the database table and return number of affected rows.&lt;br /&gt;(v) Defining function, called when session is destroyed&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;function destroy_session($sid)&lt;br /&gt;{&lt;br /&gt;    global $dbConn;&lt;br /&gt;&lt;br /&gt;    $q = sprintf('DELETE FROM sessions WHERE id=&amp;quot;%s&amp;quot;',&lt;br /&gt;                                mysqli_real_escape_string($dbConn, $sid));&lt;br /&gt;    $r = mysqli_query($dbConn, $q);&lt;br /&gt;    $_SESSION = array();&lt;br /&gt;    return mysqli_affected_rows($dbConn);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This function take single argument sessionId and delete the row based on this id.&lt;br /&gt;(vi) Defining function that is called when resource need to be freed.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;function clean_session($expire) &lt;br /&gt;{&lt;br /&gt;    global $dbConn;&lt;br /&gt;    &lt;br /&gt;    $q = sprintf('DELETE FROM sessions WHERE DATE_ADD(last_accessed, INTERVAL %d SECOND) &amp;lt; NOW()',&lt;br /&gt;                                                                                    (int)$expire);&lt;br /&gt;    $r = mysqli_query($dbConn, $q);&lt;br /&gt;    return mysqli_affected_rows($dbConn);&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This function is used to delete session data from the database based on the $expire argument it accepts.&lt;br /&gt;&lt;br /&gt;Now as we have defined all the required function, its time to call session_set_auto_save() method.&lt;br /&gt;&lt;br /&gt;Before starting the session you would need to call session_set_auto_save() method as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;&lt;br /&gt;session_set_auto_save('open_session','close_session','read_session','write_session','destroy_session','clean_session');&lt;br /&gt;&lt;br /&gt;session_start();&lt;br /&gt;&lt;br /&gt;&amp;#8230;&amp;#8230;..&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-5327538755201564393?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/5327538755201564393/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/php-storing-session-data-in-database.html#comment-form' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/5327538755201564393'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/5327538755201564393'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/php-storing-session-data-in-database.html' title='PHP: Storing session data in database'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-1172247169740109492</id><published>2009-07-02T00:47:00.000-07:00</published><updated>2009-07-02T00:52:44.009-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Applying Zend_Form decorators to all elements</title><content type='html'>After writing two posts on how to setDecorators to different form elements I think it is now time to provide a simple way to set decorators to all form elements at once.&lt;br /&gt;Take a look at the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class SimpleForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function __construct($options = null)&lt;br /&gt;    {&lt;br /&gt;        parent::__construct($options);&lt;br /&gt;        $countryList=array(&lt;br /&gt;                'United States',&lt;br /&gt;                'United Kindom',&lt;br /&gt;                'Pakistan'&lt;br /&gt;        );&lt;br /&gt;        &lt;br /&gt;        $firstName = $this-&amp;gt;createElement('text', 'firstName');&lt;br /&gt;        $firstName -&amp;gt;addValidator('alnum')&lt;br /&gt;                    -&amp;gt;addValidator('regex', false, array('/^[a-z]+/'))&lt;br /&gt;                    -&amp;gt;addValidator('stringLength', false, array(6, 20))&lt;br /&gt;                    -&amp;gt;setRequired(true)&lt;br /&gt;                    -&amp;gt; setLabel('First Name:')&lt;br /&gt;                    -&amp;gt;addFilter('StringToLower');&lt;br /&gt;        &lt;br /&gt;        $lastName = $this-&amp;gt;createElement('text', 'lastName');&lt;br /&gt;        $lastName -&amp;gt;addValidator('StringLength', false, array(6))&lt;br /&gt;                    -&amp;gt;setRequired(true)&lt;br /&gt;                    -&amp;gt; setLabel('Last Name:');&lt;br /&gt;        &lt;br /&gt;        $address1 = $this-&amp;gt;createElement('text', 'address1');&lt;br /&gt;        $address1-&amp;gt;setLabel('Address1:')&lt;br /&gt;                    -&amp;gt;addValidator('StringLength', false,array(3,50))&lt;br /&gt;                    -&amp;gt;setValue('')&lt;br /&gt;                    -&amp;gt;setRequired(true);&lt;br /&gt;        &lt;br /&gt;        $address2 = $this-&amp;gt;createElement('text', 'address2');&lt;br /&gt;        $address2-&amp;gt;setLabel('Address2:')&lt;br /&gt;                    -&amp;gt;addValidator('StringLength', false,array(3,50))&lt;br /&gt;                    -&amp;gt;setValue('')&lt;br /&gt;                    -&amp;gt;setRequired(false);&lt;br /&gt;        &lt;br /&gt;        $postalCode = $this-&amp;gt;createElement('text', 'postalCode');&lt;br /&gt;        $postalCode-&amp;gt;setLabel('Postalcode:')&lt;br /&gt;                    -&amp;gt;addValidator('StringLength', false,array(3,15))&lt;br /&gt;                    -&amp;gt;setValue('')&lt;br /&gt;                    -&amp;gt;setRequired(false);&lt;br /&gt;        &lt;br /&gt;        $city = $this-&amp;gt;createElement('text', 'city');&lt;br /&gt;        $city-&amp;gt;setLabel('City:')&lt;br /&gt;                    -&amp;gt;setValue('')&lt;br /&gt;                    -&amp;gt;setRequired(false)&lt;br /&gt;                    -&amp;gt;setAttrib('tabindex','6');&lt;br /&gt;        &lt;br /&gt;        $state = $this-&amp;gt;createElement('text', 'state');&lt;br /&gt;        $state-&amp;gt;setLabel('State:')&lt;br /&gt;                -&amp;gt;setAttrib('maxlength', 2)&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(false)&lt;br /&gt;                -&amp;gt;setAttrib('tabindex','7');&lt;br /&gt;        &lt;br /&gt;        $country = $this-&amp;gt;createElement('select', 'country');&lt;br /&gt;        $country-&amp;gt;setLabel('Country:')&lt;br /&gt;                -&amp;gt;setAttrib('class','select')&lt;br /&gt;                -&amp;gt;addMultiOptions($countryList)&lt;br /&gt;                -&amp;gt;setRequired(false);&lt;br /&gt;        &lt;br /&gt;        $phone = $this-&amp;gt;createElement('text', 'phone');&lt;br /&gt;        $phone-&amp;gt;setLabel('Phone:')&lt;br /&gt;                -&amp;gt;setAttrib('maxlength', '25')&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;                &lt;br /&gt;        $emailAddress = $this-&amp;gt;createElement('text', 'emailAddress');&lt;br /&gt;        $emailAddress-&amp;gt;setLabel('Email:')&lt;br /&gt;                    -&amp;gt;addValidator('StringLength', false,array(5,50))&lt;br /&gt;                    -&amp;gt;addValidator('EmailAddress')&lt;br /&gt;                    -&amp;gt;setValue('')&lt;br /&gt;                    -&amp;gt;setRequired(true);&lt;br /&gt;                    &lt;br /&gt;        $this-&amp;gt;addElements( array (&lt;br /&gt;                            $firstName,&lt;br /&gt;                            $lastName,&lt;br /&gt;                            $address1,&lt;br /&gt;                            $address2,&lt;br /&gt;                            $postalCode,&lt;br /&gt;                            $city,&lt;br /&gt;                            $state,&lt;br /&gt;                            $country,&lt;br /&gt;                            $phone&lt;br /&gt;            ));&lt;br /&gt;            &lt;br /&gt;        $this-&amp;gt;setElementDecorators(array(&lt;br /&gt;                    'viewHelper',&lt;br /&gt;                    'Errors',&lt;br /&gt;                    array(array('data'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'td')),&lt;br /&gt;                    array('Label',array('tag'=&amp;gt;'td')),&lt;br /&gt;                    array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;        ));&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;setDecorators(array(&lt;br /&gt;                'FormElements',&lt;br /&gt;                array(array('data'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'table')),&lt;br /&gt;                'Form'&lt;br /&gt;        ));&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;If you have read my previous post on decorators, you will easily understand the code. However those how are new to my blog and decorators may need some explanation.&lt;br /&gt;As usual we are extending our form from Zend_Form, define our constructor, call parent constructor and then define our elements.&lt;br /&gt;The most important line are after we add elements to our form. The code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;setElementDecorators(array(&lt;br /&gt;                    'viewHelper',&lt;br /&gt;                    'Errors',&lt;br /&gt;                    array(array('data'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'td')),&lt;br /&gt;                    array('Label',array('tag'=&amp;gt;'td')),&lt;br /&gt;                    array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;        ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;simply set decorators to all the elements to the form elements. Here we are define that close label in “td”, form elements in “td” and put both these in “tr”.&lt;br /&gt;If you want to set decorators to only few elements then&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;setElementDecorators(array(&lt;br /&gt;                    'viewHelper',&lt;br /&gt;                    'Errors',&lt;br /&gt;                    array(array('data'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'td')),&lt;br /&gt;                    array('Label',array('tag'=&amp;gt;'td')),&lt;br /&gt;                    array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;                    &lt;br /&gt;        ),array('firstname','lastname'));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This code will set decorators to only fistname and lastname element of the form. Rest of the form elements will be render in the default decorators.&lt;br /&gt;At the end we define&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;setDecorators(array(&lt;br /&gt;                'FormElements',&lt;br /&gt;                array(array('data'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'table')),&lt;br /&gt;                'Form'&lt;br /&gt;        ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This define the form level decorators. We are putting “table” tag after “form” tag. So all the row will be wrapped in table.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-1172247169740109492?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/1172247169740109492/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/applying-zendform-decorators-to-all.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/1172247169740109492'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/1172247169740109492'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/applying-zendform-decorators-to-all.html' title='Applying Zend_Form decorators to all elements'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-6002614767627225242</id><published>2009-07-02T00:32:00.000-07:00</published><updated>2009-07-02T00:39:11.029-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Framework Session usage and examples</title><content type='html'>Session handling was one of the boring topic in plan php atleast for me, but in Zend Framework it really shines. If you like to work with Object oriented programming, you will definitely become fan of it.&lt;br /&gt;In this article I’m going to discuss some useful techniques of using Zend Framework Session and Session namespace.&lt;br /&gt;Keep in mind that Both Zend_Session and Zend_Session_Namespace extends abstract class Zend_Session_Abstract. So both inherit methods avaliable in Zend_Session_Abstract automatically.&lt;br /&gt;If you want to go under the hood, you can open Zend/Session/Abstract.php and have a look at the functions available.&lt;br /&gt;Instead of delve into the function available, I’d rather discuss some useful techniques.&lt;br /&gt;Although you can create Zend_Session class object, however I would recommend Zend_Session_Namespace object instead. You can instantiate session as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$sess = new Zend_Session_Namespace(&amp;#8217;MyNamespace&amp;#8217;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here the argument is optional, however it is better to pass it. If don’t pass, Zend Session Namespace will assign its name a string “default”.&lt;br /&gt;To store values, you will need to do the following.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$sess-&amp;gt;username = &amp;#8216;you_name&amp;#8217;;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Later in your code, you will need to do the following to retrieve value from the session.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    $session = new Zend_Session_Namespace(&amp;#8217;MyNamespace&amp;#8217;);&lt;br /&gt;&lt;br /&gt;    $userName = $sess-&amp;gt;username;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This was a simple example of how to assign values to session and later retrieve. Now I’m going to discuss some of its important method.&lt;br /&gt;To check whether or not session exist, write the following.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    If (Zend_Session::sessionExist()) {&lt;br /&gt;&lt;br /&gt;    // do something.&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;sessionExist() is static method available in Zend_Session.&lt;br /&gt;&lt;br /&gt;Another very important method is rememberMe() available in Zend_Session. This is used to make your session persistent.&lt;br /&gt;Its syntax is&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Session::rememberMe(60*60*24*7);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The number passed as an argument specify for how long the session will be available. What I have done means that session will be there for a week.&lt;br /&gt;To destroy this you will need to call the following function on the logout of your application.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Session::forgetMe();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Another method&lt;br /&gt;destroy(bool,bool), take two Boolean arguments. This destroy the entire persistent data. Keep in mind that Zend_Session_Namespace data will not be destroyed. You can retrieve that data even after you call&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Session::destroy(false);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;To completely logout you will need to do the following&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Session::destroy(true);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;We now passed true instead of false.&lt;br /&gt;The above methods were anyhow related to Zend_Session class. To check the individual namespaces you can use the following function&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Session::namespaceIsset(&amp;#8217;MyNamespace&amp;#8217;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This will check whether the specified namespace has been set.&lt;br /&gt;To unset the particular namespace, you will need to write the following.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Session:: namespaceUnset(&amp;#8217;MyNamespace&amp;#8217;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;There are plenty of other options available. But I don’t thing you will mostly need those.&lt;br /&gt;&lt;br /&gt;If you do need extra functionality, don’t hesitate to open Zend_Session_Abstract.php, Zend_Session_Nampspace.php, and Zend_Session.php.&lt;br /&gt;If you still finding it difficult to understand, do post your comments. I’d be glad to give you solution to your problem.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-6002614767627225242?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/6002614767627225242/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-session-usage-and.html#comment-form' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6002614767627225242'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6002614767627225242'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-session-usage-and.html' title='Zend Framework Session usage and examples'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-8004446575450201538</id><published>2009-07-01T22:46:00.000-07:00</published><updated>2009-07-01T23:27:17.839-07:00</updated><title type='text'>Creating JQuery form in Zend Framework</title><content type='html'>While few months back, I wrote an article on how to make Dojo Form in Zend Framework. Although dojo has numerous features, however most of the developers around prefer JQuery and prototype.&lt;br /&gt;When Zend provide JQuery extension I wrote and article on how to use JQuery date picker.&lt;br /&gt;While most of guys visited that article demand writing an article on how to create JQuery form in Zend Framework.&lt;br /&gt;So  I’m here to show you how to use JQuery extension provide with latest version of Zend Framework for creating wonderful JQuery form.&lt;br /&gt;You will need to follow the steps bellow to create JQuery form.&lt;br /&gt;   1. Placing ZendX directory in right place&lt;br /&gt;   2. Make necessary configuration in bootstrap file&lt;br /&gt;   3. Write necessary code in your layout.phtml file.&lt;br /&gt;   4. Create JQuery form&lt;br /&gt;   5. and show that form in the template.&lt;br /&gt;&lt;br /&gt;Placing ZendX directory in right place:&lt;br /&gt;When you download latest version of Zend Framework and extract the zip file. You will see a directory called “extras”. When open that directory you will find ZendX folder. Copy this to your&lt;br /&gt;Library/ folder at the same level of your Zend directory&lt;br /&gt;You directory structure will be like this.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Library/&lt;br /&gt;    Zend/&lt;br /&gt;    ZendX/&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Making necessary configuration in bootstrap:&lt;br /&gt;After placing the directory you will need to add a bit of code in your bootstrap file.&lt;br /&gt;Add the following lines to your bootstrap file.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$view = new Zend_View();&lt;br /&gt;$view-&amp;gt;addHelperPath(&amp;quot;ZendX/JQuery/View/Helper&amp;quot;, &amp;quot;ZendX_JQuery_View_Helper&amp;quot;);&lt;br /&gt;$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();&lt;br /&gt;$viewRenderer-&amp;gt;setView($view);&lt;br /&gt;Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the code above, we instantiate our Zend_View object, set helper path, add view to the viewRenderer and finally add viewRenderer the helper broker.&lt;br /&gt;Keep in mind that if you have already instantiate Zend view in your bootstrap, you don’t need to instantiate it twice.&lt;br /&gt;Write necessary code in your layout.phtml file:&lt;br /&gt;The only line you will need to include in your layout file is&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;echo $this-&amp;gt;jQuery();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;If you don’t use two step view, you can include this line at the top of each of your view template file instead.&lt;br /&gt;Create JQuery form:&lt;br /&gt;Now you have done all the necessary configuration, its time to create the actual form.&lt;br /&gt;Create JQuery form in Zend framework is piece of cake.&lt;br /&gt;If you want to create form in your controller, write the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$form = new ZendX_JQuery_Form();&lt;br /&gt;$date1 = new ZendX_JQuery_Form_Element_DatePicker(&lt;br /&gt;                        'date1',&lt;br /&gt;                        array('label' =&amp;gt; 'Date:')&lt;br /&gt;        );&lt;br /&gt;$form-&amp;gt;addElement($date1);&lt;br /&gt;$elem = new ZendX_JQuery_Form_Element_Spinner(&lt;br /&gt;                    &amp;quot;spinner1&amp;quot;, &lt;br /&gt;                    array('label' =&amp;gt; 'Spinner:')&lt;br /&gt;        );&lt;br /&gt;$elem-&amp;gt;setJQueryParams(array(&lt;br /&gt;                'min' =&amp;gt; 0,&lt;br /&gt;                'max' =&amp;gt; 1000,&lt;br /&gt;                'start' =&amp;gt; 100)&lt;br /&gt;        );&lt;br /&gt;$form-&amp;gt;addElement($elem);&lt;br /&gt;$this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the code above we have created our JQuery form object, and add two element date and spinner to it. And then assigned the form to the view template file. Although you can create the form in your controller, however I will strongly discourage it. I will prefer using separate php file and add following code to that file.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class JQueryForm extends ZendX_JQuery_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;        $this-&amp;gt;setName('frm');&lt;br /&gt;        $this-&amp;gt;setAction('path/to/action');&lt;br /&gt;        &lt;br /&gt;        $date1 = new ZendX_JQuery_Form_Element_DatePicker(&lt;br /&gt;                'date1',&lt;br /&gt;                array('label' =&amp;gt; 'Date:')&lt;br /&gt;             );&lt;br /&gt;             &lt;br /&gt;        $this-&amp;gt;addElement($date1);&lt;br /&gt;        &lt;br /&gt;        $elem = new ZendX_JQuery_Form_Element_Spinner(&lt;br /&gt;                &amp;quot;spinner1&amp;quot;, &lt;br /&gt;                array('label' =&amp;gt; 'Spinner:')&lt;br /&gt;        );&lt;br /&gt;        &lt;br /&gt;        $elem-&amp;gt;setJQueryParams(array('min' =&amp;gt; 0, 'max' =&amp;gt; 1000, 'start' =&amp;gt; 100));&lt;br /&gt;        $this-&amp;gt;addElement($elem);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;We have extended our form from ZendX_JQuery_Form, set its method, name and action and add two elements date and spinner.&lt;br /&gt;Now in your controller/action&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    $form = new JQueryForm();&lt;br /&gt;&lt;br /&gt;    $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Showing form in the template:&lt;br /&gt;In your view template file add only the following line.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    &amp;lt;?php&lt;br /&gt;&lt;br /&gt;    echo $this-&amp;gt;form;&lt;br /&gt;&lt;br /&gt;    ?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-8004446575450201538?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/8004446575450201538/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-jquery-form-in-zend-framework.html#comment-form' title='19 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8004446575450201538'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8004446575450201538'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/creating-jquery-form-in-zend-framework.html' title='Creating JQuery form in Zend Framework'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>19</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-1480615547601153288</id><published>2009-07-01T22:36:00.000-07:00</published><updated>2009-07-01T22:41:35.953-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><category scheme='http://www.blogger.com/atom/ns#' term='Dojo'/><title type='text'>Zend Framework and dojo checkbox example</title><content type='html'>Few weeks back, I used dojo check box in my Zend framework application. Scenario  was a bit different at that time. I was submitting Zend dojo form on the click event of the checkbox. When I created a form and submitted that onclik, It didn’t give me desired results.&lt;br /&gt;I set its checked value to 1 and unchecked value to 0, however when I submited it always gave me a single value. I was looking for 0 and 1, but it always gave me 0. I thought that It was because I was not using proper submit button for the posting of form.&lt;br /&gt;However when today I used checkbox in normal zend dojo form, it gave me the same result. Oh God, how to fix it.&lt;br /&gt;However as I have played with dojo js files, so I got the solution.&lt;br /&gt;Let’s tell you the trick.&lt;br /&gt;First of all create check box as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$checkbox= $form-&amp;gt;createElement(&lt;br /&gt;                'checkBox',&lt;br /&gt;                'checkbox',&lt;br /&gt;                array(&lt;br /&gt;                    'label' =&amp;gt; 'Tricky check box',&lt;br /&gt;                    'checkedValue' =&amp;gt; 1,&lt;br /&gt;                    'uncheckedValue' =&amp;gt; 0&lt;br /&gt;                )&lt;br /&gt;            );&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now add onclick event to this checkbox element as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$checkbox-&amp;gt;setAttrib('onclick','changeValue()');&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now in your view, where you display this form, write the following javascript function&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;script&amp;gt;&lt;br /&gt;function changeValue()&lt;br /&gt;{&lt;br /&gt;    if(dijit.byId('checkbox').checked){&lt;br /&gt;        dijit.byId('checkbox').setValue('1');&lt;br /&gt;    } else {&lt;br /&gt;        dijit.byId('checkbox').setValue('0');&lt;br /&gt;        dijit.byId('checkbox').checked=false;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The above code isn’t simple?&lt;br /&gt;&lt;br /&gt;Hmm. First we see if we have checked the checkbox, if yes we assign value 1 to it, if not we assign it value 0 and set its checked status to false. This will uncheck the checkbox.&lt;br /&gt;&lt;br /&gt;That’s it. Submit your form and you will get desired results.&lt;br /&gt;&lt;br /&gt;Doesn’t it help you. Do you have smarter solution than this.&lt;br /&gt;&lt;br /&gt;Tell me……&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-1480615547601153288?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/1480615547601153288/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-and-dojo-checkbox.html#comment-form' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/1480615547601153288'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/1480615547601153288'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-and-dojo-checkbox.html' title='Zend Framework and dojo checkbox example'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-84308953829383419</id><published>2009-07-01T11:43:00.000-07:00</published><updated>2009-07-01T11:56:47.866-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork tutorial'/><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Framework Form(Zend_Form) tutorial</title><content type='html'>I got “The Zahir”, a novel by Paula Coelho about a month back, very sweat one and highly intrigued. It was highly entertaining and most importantly author shared his experiences in a nice way. I learned plenty of new ideas.&lt;br /&gt;Eh, you may think that I am insane, supposed to write about Zend Framework, but discussing a novel.&lt;br /&gt;Well, novel can not only be a good companion of yours, but it also put shade of light on simple things from many angles. This make you think dynamically.&lt;br /&gt;If you are solving a puzzle or implementing your logic, do not think straight forward, give multiple tries and chose a more appropriate solution. Solving a problem will not be hard. You should chose a solution that require less code, small maintenance overhead and most importantly one that will be less resource intensive.&lt;br /&gt;Now lets stick to the topic and discuss how you can use Zend_Form component for creating html form easily, handling filters and errors messages and how to see how easily you can fetch data from the data source and present that in html form and let the visitors change/modify the existing data and save changes to the data source.&lt;br /&gt;I am gona break this topic in three steps.&lt;br /&gt;1. Creating Zend_Form&lt;br /&gt;  Although I’ve already discussed creation of Zend_Form in some of my articles but it will be better to discuss it here again.&lt;br /&gt;Creating Zend form is simple is this.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class CustomForm extend Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;defined a class by extending it from Zend_Form. This allow access to many of methods already defined in Zend_Form.&lt;br /&gt;The only thing you need to do is to override init() method and create your own element such as input box, select statement, checkboxes, radio buttons and so on.&lt;br /&gt;Defining your own elements don’t take much code. Have a look at the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class CustomForm extend Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;        $this-&amp;gt;setAction('process/form');&lt;br /&gt;        &lt;br /&gt;        $username = $this-&amp;gt;createElement('text','username');&lt;br /&gt;        $username-&amp;gt;setLabel('Username:')&lt;br /&gt;                -&amp;gt;setAttrib('size',50);&lt;br /&gt;            &lt;br /&gt;        $this-&amp;gt;addElement($username);&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the code above we have overridden init() method of Zend_Form, set the form request method and action and then defined input element called username. You can put as many elements in this form as you wish. The last statement is used to add element to the forms. To add several elements to the form at once, use addElements() passing array of elements as an argument. You will look an example in the next example.&lt;br /&gt;&lt;br /&gt;My entire form look likes&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class CustomForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;&lt;br /&gt;        $id = $this-&amp;gt;createElement('hidden','id');&lt;br /&gt;        $firstname = $this-&amp;gt;createElement('text','firstname');&lt;br /&gt;        $firstname-&amp;gt;setLabel('First Name:')&lt;br /&gt;                    -&amp;gt;setAttrib('size',50);&lt;br /&gt;        $lastname = $this-&amp;gt;createElement('text','lastname');&lt;br /&gt;        $lastname-&amp;gt;setLabel('Last Name:')&lt;br /&gt;                -&amp;gt;setAttrib('size',50);&lt;br /&gt;        $username = $this-&amp;gt;createElement('text','username');&lt;br /&gt;        $username-&amp;gt;setLabel('Username:')&lt;br /&gt;                -&amp;gt;setAttrib('size',50);&lt;br /&gt;        $email = $this-&amp;gt;createElement('text','email');&lt;br /&gt;        $email-&amp;gt;setLabel('Email:')&lt;br /&gt;                -&amp;gt;setAttrib('size',50);&lt;br /&gt;        $password = $this-&amp;gt;createElement('password','password');&lt;br /&gt;        $password-&amp;gt;setLabel('Password:')&lt;br /&gt;                    -&amp;gt;setAttrib('size',50);&lt;br /&gt;&lt;br /&gt;        $password2 = $this-&amp;gt;createElement('password','password2');&lt;br /&gt;        $password2-&amp;gt;setLabel('Confirm Password::')&lt;br /&gt;                    -&amp;gt;setAttrib('size',50);&lt;br /&gt;        $register = $this-&amp;gt;createElement('submit','register');&lt;br /&gt;        $register-&amp;gt;setLabel(&amp;quot;Register&amp;quot;)&lt;br /&gt;                -&amp;gt;setIgnore(true);&lt;br /&gt;&lt;br /&gt;        $this-&amp;gt;addElements(array(&lt;br /&gt;            $firstname,&lt;br /&gt;            $lastname,&lt;br /&gt;            $username,&lt;br /&gt;            $email,&lt;br /&gt;            $password,&lt;br /&gt;            $password2,&lt;br /&gt;            $id,&lt;br /&gt;            $register&lt;br /&gt;        ));&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Most of the functions are simple and self explanatory. The only method that I think I’d better explain here is setIgnore() method. The method setIgnore() has a very valuable usage. Well, if we see the entire form you will feel that we need all values when form is submitted. The only value we don’t need is the value of the submit button as this only used to submit the form. We are not interested in its value, so we call setIgnore() method passing Boolean value true.&lt;br /&gt;&lt;br /&gt;2. As we have now created a form, next step is to create its object in controller and write code that will save data for us. Create a controller as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class UsersController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;    .....&lt;br /&gt;    &lt;br /&gt;    public function addAction()&lt;br /&gt;    {&lt;br /&gt;        //$this-&amp;gt;_helper-&amp;gt;layout-&amp;gt;disableLayout();&lt;br /&gt;        $users  = new Users();&lt;br /&gt;        $form = new CustomForm();&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;    &lt;br /&gt;&lt;br /&gt;        if ($this-&amp;gt;getRequest()-&amp;gt;isPost()) {&lt;br /&gt;        $formData  = $this-&amp;gt;_request-&amp;gt;getPost();&lt;br /&gt;            if ($form-&amp;gt;isValid($formData)) {&lt;br /&gt;                if ($formData['password'] != $formData['password2']) {&lt;br /&gt;                    $this-&amp;gt;view-&amp;gt;errorMsg = &amp;quot;Password and Confirm Password must match.&amp;quot;;&lt;br /&gt;                    $this-&amp;gt;render('add');&lt;br /&gt;                    return;&lt;br /&gt;                }&lt;br /&gt;            unset($formData['password2']);&lt;br /&gt;            unset($formData['register']);&lt;br /&gt;            $users-&amp;gt;insert($formData);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;What we are doing here, is pretty simple. Create an object of Users model. Well I haven’t discussed Users model yet. I would discuss it for you soon. The next line creates an object of the form created earlier. Next we assign the form to the view template, in our case the template is add.phtml.&lt;br /&gt;Next few lines are of much importance.&lt;br /&gt;We check whether the request is first one or the post back. If form has been submitted, method $this-&gt;getRequest()-&gt;isPost() return ture. In this case we will need to take care of the data being submitted.&lt;br /&gt;To handle the post back we get the data been posted back through form, check its validity, check if the password and confirm password matches, and insert the values in the “users” table using $users-&gt;insert(); statement.&lt;br /&gt;If form is not valid, the code for inserting the data in the database will not be executed.&lt;br /&gt;Now lets discuss “Users” model.&lt;br /&gt;We have a table in our database called “users” containing different fields such as username, firstname, lastname etc.&lt;br /&gt;We will need to create our model as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class Users extends Zend_Db_Table&lt;br /&gt;{&lt;br /&gt;    protected $_name = &amp;quot;users&amp;quot;;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;That’s it, a simple model.&lt;br /&gt;3. The third step in creating a full fledge form application in Zend Framework is presentation layer, called view/template.&lt;br /&gt;In your scripts/users/ directory create add.phtml and put the following code in it&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;h3&amp;gt;Add User&amp;lt;/h3&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;    if ($this-&amp;gt;errorMsg) {&lt;br /&gt;    echo $this-&amp;gt;errorMsg;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;    // for displaying form&lt;br /&gt;    echo $this-&amp;gt;form;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The code above is self explanatory.&lt;br /&gt;The above process only shows a form and submits data to the database. If you want to create edit form, you will need to make a bit of change in your controller.&lt;br /&gt;Let’s create another action called editAction containing the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class UsersController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;    .....&lt;br /&gt;    &lt;br /&gt;    public function editAction()&lt;br /&gt;    {&lt;br /&gt;        //$this-&amp;gt;_helper-&amp;gt;layout-&amp;gt;disableLayout();&lt;br /&gt;        $users  = new Users();&lt;br /&gt;        $form = new CustomForm();&lt;br /&gt;        &lt;br /&gt;        $id = $this-&amp;gt;_getParam(&amp;quot;id&amp;quot;,1);&lt;br /&gt;        $select = $users-&amp;gt;select()&lt;br /&gt;                -&amp;gt;where(&amp;quot;id = ?&amp;quot;,$id);&lt;br /&gt;        $data = $users-&amp;gt;fetchRow($select);&lt;br /&gt;        $form-&amp;gt;populate($data-&amp;gt;toArray());&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;        if ($this-&amp;gt;getRequest()-&amp;gt;isPost()) {&lt;br /&gt;        $formData  = $this-&amp;gt;_request-&amp;gt;getPost();&lt;br /&gt;            if ($form-&amp;gt;isValid($formData)) {&lt;br /&gt;                if ($formData['password'] != $formData['password2']) {&lt;br /&gt;                    $this-&amp;gt;view-&amp;gt;errorMsg = &amp;quot;Password and Confirm Password must match.&amp;quot;;&lt;br /&gt;                    $this-&amp;gt;render('add');&lt;br /&gt;                    return;&lt;br /&gt;                }&lt;br /&gt;            unset($formData['password2']);&lt;br /&gt;            unset($formData['register']);&lt;br /&gt;            //Zend_Debug::dump($formData);exit;&lt;br /&gt;            $users-&amp;gt;update($formData,&amp;quot;id = $id&amp;quot;);&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;You can clearly see that I’ve made only few lines of changes.&lt;br /&gt;First I get the id of the user through $this-&gt;_getParam() method. I then create a select statement on the users table and then fetch a row. Once I get the data row, I populate the form using populate() method.&lt;br /&gt;The only thing you will need now, is to create a view template in your scripts/users/ directory named edit.phtml and write the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;    if ($this-&amp;gt;errorMsg) {&lt;br /&gt;    echo $this-&amp;gt;errorMsg;&lt;br /&gt;}&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;?php&lt;br /&gt;    // for displaying form&lt;br /&gt;    echo $this-&amp;gt;form;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Well I was thinking to explain everything in three steps, but I think it would be incomplete if I don’t explain how to show the data inserted in the database. For this reason I going to add 4th step.&lt;br /&gt;4. Showing list of data&lt;br /&gt;Create an action called indexAction in your controller with the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class UsersController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;    public function indexAction()&lt;br /&gt;    {&lt;br /&gt;        //$this-&amp;gt;_helper-&amp;gt;layout-&amp;gt;disableLayout();&lt;br /&gt;        $users  = new Users();&lt;br /&gt;        $data  = $users-&amp;gt;fetchAll($users-&amp;gt;select());&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;data = $data-&amp;gt;toArray();&lt;br /&gt;        //Zend_Debug::dump($data-&amp;gt;toArray());&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    .....&lt;br /&gt;    &lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;First we create an object of our mode. And then fetch the data using the fetchAll() method. The last statement assigns the fetched data to the view template.&lt;br /&gt;Now create scripts/users/index.phtml and write the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;h4&amp;gt;List of users&amp;lt;/h4&amp;gt;&lt;br /&gt;&amp;lt;h5&amp;gt;&amp;lt;a href=&amp;quot;add&amp;quot;&amp;gt;Add new user&amp;lt;/a&amp;gt;&amp;lt;/h5&amp;gt;&lt;br /&gt;&amp;lt;table&amp;gt;&lt;br /&gt;    &amp;lt;thead&amp;gt;    &lt;br /&gt;        &amp;lt;tr&amp;gt;&lt;br /&gt;            &amp;lt;th&amp;gt;First Name&amp;lt;/th&amp;gt;&lt;br /&gt;            &amp;lt;th&amp;gt;Last Name&amp;lt;/th&amp;gt;&lt;br /&gt;            &amp;lt;th&amp;gt;Username&amp;lt;/th&amp;gt;&lt;br /&gt;            &amp;lt;th&amp;gt;Email&amp;lt;/th&amp;gt;&lt;br /&gt;            &amp;lt;th&amp;gt;Action&amp;lt;/th&amp;gt;&lt;br /&gt;        &amp;lt;/tr&amp;gt;&lt;br /&gt;    &amp;lt;/thead&amp;gt;&lt;br /&gt;    &amp;lt;tboody&amp;gt;&lt;br /&gt;        &amp;lt;?php foreach ($this-&amp;gt;data as $d) {?&amp;gt;&lt;br /&gt;        &amp;lt;tr&amp;gt;&lt;br /&gt;            &amp;lt;td&amp;gt;&amp;lt;?=$d['firstname']?&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;            &amp;lt;td&amp;gt;&amp;lt;?=$d['lastname']?&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;            &amp;lt;td&amp;gt;&amp;lt;?=$d['username']?&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;            &amp;lt;td&amp;gt;&amp;lt;?=$d['email']?&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;            &amp;lt;td&amp;gt;&amp;lt;a href=&amp;quot;edit/id/&amp;lt;?=$d['id']?&amp;gt;&amp;quot;&amp;gt;Edit&amp;lt;/a&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;        &amp;lt;/tr&amp;gt;&lt;br /&gt;        &amp;lt;?php }?&amp;gt;&lt;br /&gt;    &amp;lt;/tbody&amp;gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here we are creating a table that shows the list of data. I don’t think this need to be explained.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-84308953829383419?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/84308953829383419/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-formzendform-tutorial.html#comment-form' title='7 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/84308953829383419'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/84308953829383419'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-formzendform-tutorial.html' title='Zend Framework Form(Zend_Form) tutorial'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>7</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-3453572382529116303</id><published>2009-07-01T10:54:00.000-07:00</published><updated>2009-07-01T11:16:51.514-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><category scheme='http://www.blogger.com/atom/ns#' term='Dojo'/><title type='text'>Zend Framework and dojo- Auto Complete Example</title><content type='html'>Creation of auto complete in Zend Framework using dojo is like a piece of cake. In one of my previous post I discuss how to create filtering select and populate that using dojo and ajax.&lt;br /&gt;Here I am going to discuss how to create auto complete with combo box. The auto complete textbox will automatically/dynamically fetch data from the database.&lt;br /&gt;So lets get started.&lt;br /&gt;First of all create following functions in you controller.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public function getForm()&lt;br /&gt;{&lt;br /&gt;    if (null === $this-&amp;gt;_form) {&lt;br /&gt;        $this-&amp;gt;_form = new Zend_Form();&lt;br /&gt;        $this-&amp;gt;_form-&amp;gt;setMethod('get')&lt;br /&gt;                -&amp;gt;setAction($this-&amp;gt;getRequest()-&amp;gt;getBaseUrl() . '/test/process')&lt;br /&gt;                -&amp;gt;addElements(array(&lt;br /&gt;                'test' =&amp;gt; array(&lt;br /&gt;                    'type' =&amp;gt; 'text', &lt;br /&gt;                    'options' =&amp;gt; array(&lt;br /&gt;                            'filters'        =&amp;gt; array('StringTrim'),&lt;br /&gt;                            'dojoType'       =&amp;gt; array('dijit.form.ComboBox'),&lt;br /&gt;                            'store'          =&amp;gt; 'testStore',&lt;br /&gt;                            'autoComplete'   =&amp;gt; 'false',&lt;br /&gt;                            'hasDownArrow'   =&amp;gt; 'true',&lt;br /&gt;                            'label' =&amp;gt; 'Your input:',&lt;br /&gt;                    )),&lt;br /&gt;                'go' =&amp;gt; array('type' =&amp;gt; 'submit',&lt;br /&gt;                'options' =&amp;gt; array('label' =&amp;gt; 'Go!'))&lt;br /&gt;                ));&lt;br /&gt;        }&lt;br /&gt;    return $this-&amp;gt;_form;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the above code define a function and create a form adding it a combo box.&lt;br /&gt;The important attributes of the combo box are&lt;br /&gt;dojoType, store and autocomplet.&lt;br /&gt;Next create the following actions in your controller where you defined getForm() method.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class DojoController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;    public function autocompleteAction()&lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;form = $this-&amp;gt;getForm();&lt;br /&gt;    }&lt;br /&gt;    public function recordsAction()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the above code we get the form by calling the method defined and assign it to the view template.&lt;br /&gt;Next in the view template file write.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Zend_Dojo_View_Helper_Dojo::setUseDeclarative();&lt;br /&gt;$this-&amp;gt;dojo()-&amp;gt;setLocalPath('http://localhost/z/js/dojo/dojo/dojo.js')&lt;br /&gt;            -&amp;gt;addStyleSheetModule('dijit.themes.tundra')&lt;br /&gt;            -&amp;gt;addStylesheet('http://localhost/z/js/dojo/dojox/grid/_grid/tundraGrid.css');&lt;br /&gt;echo $this-&amp;gt;dojo();&lt;br /&gt;?&amp;gt;&lt;br /&gt;&amp;lt;script type=&amp;quot;text/javascript&amp;quot;&amp;gt;&lt;br /&gt;    dojo.require(&amp;quot;dojox.data.QueryReadStore&amp;quot;);&lt;br /&gt;    dojo.require(&amp;quot;dijit.form.ComboBox&amp;quot;);&lt;br /&gt;    dojo.require(&amp;quot;dojo.parser&amp;quot;);&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;div dojoType=&amp;quot;dojox.data.QueryReadStore&amp;quot; jsId=&amp;quot;testStore&amp;quot; url=&amp;quot;records&amp;quot;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&amp;lt;?&lt;br /&gt;    echo $this-&amp;gt;form;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the code above we first tell zend that we want to use declarative mode than programmatic which is default.&lt;br /&gt;Next we set local path to dojo.js and necessary css and theme.&lt;br /&gt;Next we specify which dojo js files we require.&lt;br /&gt;The most important thing in the above code is&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;div dojoType=&amp;#8221;dojox.data.QueryReadStore&amp;#8221; jsId=&amp;#8221;testStore&amp;#8221; url=&amp;#8221;records&amp;#8221;&amp;gt;&amp;lt;/div&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here we specify dojoType and jsId. Keep in mind that the jsId is same to the combobox store attribute.&lt;br /&gt;Another important thing is url of the div. this url is used by dojo QueryReadStore to pull data from the action.&lt;br /&gt;To populate our combo box in  the records action of the Dojo Controller write the following.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public function recordsAction()&lt;br /&gt;{&lt;br /&gt;    $db=Zend_Registry::get('db');&lt;br /&gt;    $sql = 'SELECT name FROM company';&lt;br /&gt;    $result = $db-&amp;gt;fetchAll($sql);&lt;br /&gt;    $dojoData= new Zend_Dojo_Data('name',$result,'id');&lt;br /&gt;    echo $dojoData-&amp;gt;toJson();&lt;br /&gt;    exit;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The above code is simple to understand. We first get reference to the db object store in the bootsrap.&lt;br /&gt;Next we write sql. Keep in mind that I have company table with name field in my database.&lt;br /&gt;Next I fetch all data(name). give it to Zend_Dojo_Data. And convert resultant data to Json.&lt;br /&gt;That’s it.&lt;br /&gt;Cheers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-3453572382529116303?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/3453572382529116303/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-and-dojo-auto-complete.html#comment-form' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/3453572382529116303'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/3453572382529116303'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-and-dojo-auto-complete.html' title='Zend Framework and dojo- Auto Complete Example'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-8190179655302555283</id><published>2009-07-01T10:04:00.000-07:00</published><updated>2009-07-01T11:20:41.185-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork tutorial'/><title type='text'>Zend Framework sign up and authentication</title><content type='html'>After writing separate articles on different Zend framework topics, its now time to write a full fledge tutorials. I am starting from a simple sign up and login authentication example and hopefully will discuss some advance topic in future.&lt;br /&gt;&lt;br /&gt;So lets get started.&lt;br /&gt;&lt;br /&gt;First create a table in your database by executing the following sql query.&lt;br /&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    CREATE TABLE &amp;#8216;users&amp;#8217; (&lt;br /&gt;&lt;br /&gt;      &amp;#8216;id&amp;#8217; int(11) NOT NULL auto_increment,&lt;br /&gt;&lt;br /&gt;      &amp;#8216;firstname&amp;#8217; varchar(100) default NULL,&lt;br /&gt;&lt;br /&gt;      &amp;#8216;lastname&amp;#8217; varchar(100) default NULL,&lt;br /&gt;&lt;br /&gt;      &amp;#8216;email&amp;#8217; varchar(255) NOT NULL,&lt;br /&gt;&lt;br /&gt;      &amp;#8216;username&amp;#8217; varchar(100) NOT NULL,&lt;br /&gt;&lt;br /&gt;      &amp;#8216;password&amp;#8217; varchar(15) NULL,&lt;br /&gt;&lt;br /&gt;      PRIMARY KEY  (&amp;#8217;id&amp;#8217;)&lt;br /&gt;&lt;br /&gt;    )&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Next create a model against this table in your application/model/ directory. I am creating Users.php and writing the following code in it.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    &amp;lt;?&lt;br /&gt;&lt;br /&gt;    class Users extends Zend_Db_Table&lt;br /&gt;&lt;br /&gt;    {&lt;br /&gt;&lt;br /&gt;                protected $_name=&amp;#8221;users&amp;#8221;;&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    ?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now create a controller named AuthController.php in application/controllers/ directory and place the following code in it&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class AuthController extends Zend_Controller_Action&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    public function loginAction()&lt;br /&gt;    {&lt;br /&gt;    } &lt;br /&gt;    public function signupAction()&lt;br /&gt;    {&lt;br /&gt;    } &lt;br /&gt;    public function logoutAction()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;    public function homeAction()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;As we have now create our controller and three actions, we will need to create templates files for actions. Go application/views/scripts and create a folder named “auth” and create three files in application/views/scripts/auth named&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    login.phtml&lt;br /&gt;&lt;br /&gt;    signup.phtml&lt;br /&gt;&lt;br /&gt;    logout.phtml&lt;br /&gt;&lt;br /&gt;    home.phtml&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;As we will need to have forms for sign up and login so we are going to create to files named “LoginForm.php” and “RegistrationForm.php” for these forms in application/forms/ directory.&lt;br /&gt;&lt;br /&gt;In LoginForm.php place the following code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class LoginForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class LoginForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;and in the RegistrationForm.php place the following code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class RegistrationForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;So far you can see that we have created all our necessary files.&lt;br /&gt;&lt;br /&gt;No lets put the application logic in these files.&lt;br /&gt;&lt;br /&gt;We are starting from the forms first.&lt;br /&gt;&lt;br /&gt;In LoginForm.php, write the following code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class LoginForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $username = $this-&amp;gt;createElement(&amp;#8217;text&amp;#8217;,'username&amp;#8217;);&lt;br /&gt;        $username-&amp;gt;setLabel(&amp;#8217;Username: *&amp;#8217;)&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;                &lt;br /&gt;        $password = $this-&amp;gt;createElement(&amp;#8217;password&amp;#8217;,'password&amp;#8217;);&lt;br /&gt;        $password-&amp;gt;setLabel(&amp;#8217;Password: *&amp;#8217;)&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;                &lt;br /&gt;        $signin = $this-&amp;gt;createElement(&amp;#8217;submit&amp;#8217;,&amp;#8217;signin&amp;#8217;);&lt;br /&gt;        $signin-&amp;gt;setLabel(&amp;#8217;Sign in&amp;#8217;)&lt;br /&gt;                -&amp;gt;setIgnore(true);&lt;br /&gt;                &lt;br /&gt;        $this-&amp;gt;addElements(array(&lt;br /&gt;                        $username,&lt;br /&gt;                        $password,&lt;br /&gt;                        $signin,&lt;br /&gt;        ));&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the above form we are creating two text elements named “usernam” and “password”, set their labels and setRequred to true. Next we create a submit button.&lt;br /&gt;Similarly in RegistrationForm.php, write the following code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class RegistrationForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function init()&lt;br /&gt;    {&lt;br /&gt;        $firstname = $this-&amp;gt;createElement('text','firstname');&lt;br /&gt;        $firstname-&amp;gt;setLabel('First Name:')&lt;br /&gt;                    -&amp;gt;setRequired(false);&lt;br /&gt;                    &lt;br /&gt;        $lastname = $this-&amp;gt;createElement('text','lastname');&lt;br /&gt;        $lastname-&amp;gt;setLabel('Last Name:')&lt;br /&gt;                    -&amp;gt;setRequired(false);&lt;br /&gt;                    &lt;br /&gt;        $email = $this-&amp;gt;createElement('text','email');&lt;br /&gt;        $email-&amp;gt;setLabel('Email: *')&lt;br /&gt;                -&amp;gt;setRequired(false);&lt;br /&gt;                &lt;br /&gt;        $username = $this-&amp;gt;createElement('text','username');&lt;br /&gt;        $username-&amp;gt;setLabel('Username: *')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;                &lt;br /&gt;        $password = $this-&amp;gt;createElement('password','password');&lt;br /&gt;        $password-&amp;gt;setLabel('Password: *')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;                &lt;br /&gt;        $confirmPassword = $this-&amp;gt;createElement('password','confirmPassword');&lt;br /&gt;        $confirmPassword-&amp;gt;setLabel('Confirm Password: *')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;                &lt;br /&gt;        $register = $this-&amp;gt;createElement('submit','register');&lt;br /&gt;        $register-&amp;gt;setLabel('Sign up')&lt;br /&gt;                -&amp;gt;setIgnore(true);&lt;br /&gt;                &lt;br /&gt;        $this-&amp;gt;addElements(array(&lt;br /&gt;                        $firstname,&lt;br /&gt;                        $lastname,&lt;br /&gt;                        $email,&lt;br /&gt;                        $username,&lt;br /&gt;                        $password,&lt;br /&gt;                        $confirmPassword,&lt;br /&gt;                        $register&lt;br /&gt;        ));&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the above code we have created several elements and place them in the form. Keep in mind that we have place * next to compulsory elements labels.&lt;br /&gt;As we have now created our forms, next step is to display these in the templates files. However to do this we will first need to initialize these in our controller&lt;br /&gt;So in AuthController.php, write the following code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class AuthController extends Zend_Controller_Action&lt;br /&gt;{&lt;br /&gt;    public function homeAction()&lt;br /&gt;    {&lt;br /&gt;        $storage = new Zend_Auth_Storage_Session();&lt;br /&gt;        $data = $storage-&amp;gt;read();&lt;br /&gt;        if(!$data){&lt;br /&gt;            $this-&amp;gt;_redirect('auth/login');&lt;br /&gt;        }&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;username = $data-&amp;gt;username;                &lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public function loginAction()&lt;br /&gt;    {&lt;br /&gt;        $users = new Users();&lt;br /&gt;        $form = new LoginForm();&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;        if($this-&amp;gt;getRequest()-&amp;gt;isPost()){&lt;br /&gt;            if($form-&amp;gt;isValid($_POST)){&lt;br /&gt;                $data = $form-&amp;gt;getValues();&lt;br /&gt;                $auth = Zend_Auth::getInstance();&lt;br /&gt;                $authAdapter = new Zend_Auth_Adapter_DbTable($users-&amp;gt;getAdapter(),'users');&lt;br /&gt;                $authAdapter-&amp;gt;setIdentityColumn('username')&lt;br /&gt;                            -&amp;gt;setCredentialColumn('password');&lt;br /&gt;                $authAdapter-&amp;gt;setIdentity($data['username'])&lt;br /&gt;                            -&amp;gt;setCredential($data['password']);&lt;br /&gt;                $result = $auth-&amp;gt;authenticate($authAdapter);&lt;br /&gt;                if($result-&amp;gt;isValid()){&lt;br /&gt;                    $storage = new Zend_Auth_Storage_Session();&lt;br /&gt;                    $storage-&amp;gt;write($authAdapter-&amp;gt;getResultRowObject());&lt;br /&gt;                    $this-&amp;gt;_redirect('auth/home');&lt;br /&gt;                } else {&lt;br /&gt;                    $this-&amp;gt;view-&amp;gt;errorMessage = &amp;quot;Invalid username or password. Please try again.&amp;quot;;&lt;br /&gt;                }         &lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    public function signupAction()&lt;br /&gt;    {&lt;br /&gt;        $users = new Users();&lt;br /&gt;        $form = new RegistrationForm();&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;form=$form;&lt;br /&gt;        if($this-&amp;gt;getRequest()-&amp;gt;isPost()){&lt;br /&gt;            if($form-&amp;gt;isValid($_POST)){&lt;br /&gt;                $data = $form-&amp;gt;getValues();&lt;br /&gt;                if($data['password'] != $data['confirmPassword']){&lt;br /&gt;                    $this-&amp;gt;view-&amp;gt;errorMessage = &amp;quot;Password and confirm password don't match.&amp;quot;;&lt;br /&gt;                    return;&lt;br /&gt;                }&lt;br /&gt;                if($users-&amp;gt;checkUnique($data['username'])){&lt;br /&gt;                    $this-&amp;gt;view-&amp;gt;errorMessage = &amp;quot;Name already taken. Please choose      another one.&amp;quot;;&lt;br /&gt;                    return;&lt;br /&gt;                }&lt;br /&gt;                unset($data['confirmPassword']);&lt;br /&gt;                $users-&amp;gt;insert($data);&lt;br /&gt;                $this-&amp;gt;_redirect('auth/login');&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;    &lt;br /&gt;    public function logoutAction()&lt;br /&gt;    {&lt;br /&gt;        $storage = new Zend_Auth_Storage_Session();&lt;br /&gt;        $storage-&amp;gt;clear();&lt;br /&gt;        $this-&amp;gt;_redirect('auth/login');&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;It will be hard for beginners to understand the above code. So lets break it and see what this code is all about.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public function homeAction()&lt;br /&gt;    {&lt;br /&gt;        $storage = new Zend_Auth_Storage_Session();&lt;br /&gt;        $data = $storage-&amp;gt;read();&lt;br /&gt;        if(!$data){&lt;br /&gt;            $this-&amp;gt;_redirect('auth/login');&lt;br /&gt;        }&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;username = $data-&amp;gt;username;                &lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The above code is very simple. We first create instance of Zend_Auth_Storage_Session class. Next we call its read method. This will return a row of records if the users is authenticated, otherwise null.&lt;br /&gt;We check if the data is null. If yes, we redirect our page to the login action.&lt;br /&gt;If data is found, it means that user is authenticated and we assign username to the view template. So display welcome message in our home.phtml template, open views/scripts/auth/home.phtml and write the following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    Welcome &amp;lt;?=$this-&amp;gt;username?&amp;gt;,&amp;lt;br&amp;gt;&lt;br /&gt;&lt;br /&gt;    This is your home page&amp;lt;br&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;a href=&amp;#8221;&amp;lt;?=$this-&amp;gt;url(array(&amp;#8217;controller&amp;#8217;=&amp;gt;&amp;#8217;auth&amp;#8217;,'action&amp;#8217;=&amp;gt;&amp;#8217;logout&amp;#8217;))?&amp;gt;&amp;#8221;&amp;gt;click here to logout&amp;lt;/a&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the code above we have a link to the logout action, which simply destroy our session.&lt;br /&gt;Next&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public function loginAction()&lt;br /&gt;    {&lt;br /&gt;        $users = new Users();&lt;br /&gt;        $form = new LoginForm();&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;form = $form;&lt;br /&gt;        if($this-&amp;gt;getRequest()-&amp;gt;isPost()){&lt;br /&gt;            if($form-&amp;gt;isValid($_POST)){&lt;br /&gt;                $data = $form-&amp;gt;getValues();&lt;br /&gt;                $auth = Zend_Auth::getInstance();&lt;br /&gt;                $authAdapter = new Zend_Auth_Adapter_DbTable($users-&amp;gt;getAdapter(),'users');&lt;br /&gt;                $authAdapter-&amp;gt;setIdentityColumn('username')&lt;br /&gt;                            -&amp;gt;setCredentialColumn('password');&lt;br /&gt;                $authAdapter-&amp;gt;setIdentity($data['username'])&lt;br /&gt;                            -&amp;gt;setCredential($data['password']);&lt;br /&gt;                $result = $auth-&amp;gt;authenticate($authAdapter);&lt;br /&gt;                if($result-&amp;gt;isValid()){&lt;br /&gt;                    $storage = new Zend_Auth_Storage_Session();&lt;br /&gt;                    $storage-&amp;gt;write($authAdapter-&amp;gt;getResultRowObject());&lt;br /&gt;                    $this-&amp;gt;_redirect('auth/home');&lt;br /&gt;                } else {&lt;br /&gt;                    $this-&amp;gt;view-&amp;gt;errorMessage = &amp;quot;Invalid username or password. Please try again.&amp;quot;;&lt;br /&gt;                }         &lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the fist two lines we create instances of our model and login form with statements&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    $users = new Users();&lt;br /&gt;&lt;br /&gt;    $form = new LoginForm();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the third line we assign form instance to view template for display purpose.&lt;br /&gt;The logic of logging in is defined in the next lines&lt;br /&gt;We first check that the users has posted the request. If yes we check that he has submitted valid form. If both the condition return true, we get the values submitted as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$data = $form-&amp;gt;getValues();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Next we create instance of Zend_Auth with code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$auth = Zend_Auth::getInstance();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;and $authAdapter with&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$authAdapter = new Zend_Auth_Adapter_DbTable($users-&amp;gt;getAdapter(),&amp;#8217;users&amp;#8217;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;To perform authentication we will need to either use existing Adapters provided by Zend or create our own.&lt;br /&gt;&lt;br /&gt;Here I am using DbTable Adapter provided by Zend, giving adapter and database table name. our table name is users.&lt;br /&gt;Next we set identity and credential columns.&lt;br /&gt;After that we give posted values to the $adapter.&lt;br /&gt;To perform authentication we will need to call Zend_Auth authenticate() method, for this we write&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$result = $auth-&amp;gt;authenticate($authAdapter);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Next we check if the result is valid with statement $result-&gt;isValid(). This either return true or false. If it return true it means that we found a record in the database.&lt;br /&gt;If valid record is found we create session instance and store the user data in the session with statements&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$storage = new Zend_Auth_Storage_Session();&lt;br /&gt;$storage-&amp;gt;write($authAdapter-&amp;gt;getResultRowObject());&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;and redirect our request to home action.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;_redirect(&amp;#8217;auth/home&amp;#8217;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;If result is not valid we assign error message to our template file&lt;br /&gt;In application/views/scripts/login.phml, write the following&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    &amp;lt;?&lt;br /&gt;&lt;br /&gt;    if(isset($this-&amp;gt;errorMessage)){&lt;br /&gt;&lt;br /&gt;                echo $this-&amp;gt;errorMessage;&lt;br /&gt;&lt;br /&gt;    }?&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;?&lt;br /&gt;&lt;br /&gt;                echo $this-&amp;gt;form;&lt;br /&gt;&lt;br /&gt;    ?&amp;gt;&lt;br /&gt;&lt;br /&gt;    &amp;lt;a href=&amp;#8221;&amp;lt;?=$this-&amp;gt;url(array(&amp;#8217;controller&amp;#8217;=&amp;gt;&amp;#8217;auth&amp;#8217;,'action&amp;#8217;=&amp;gt;&amp;#8217;signup&amp;#8217;))?&amp;gt;&amp;#8221;&amp;gt;New users click here?&amp;lt;/a&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the code above we first check the error message, if set we display it.&lt;br /&gt;In the next line we display our login form.&lt;br /&gt;Next&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public function signupAction()&lt;br /&gt;    {&lt;br /&gt;        $users = new Users();&lt;br /&gt;        $form = new RegistrationForm();&lt;br /&gt;        $this-&amp;gt;view-&amp;gt;form=$form;&lt;br /&gt;        if($this-&amp;gt;getRequest()-&amp;gt;isPost()){&lt;br /&gt;            if($form-&amp;gt;isValid($_POST)){&lt;br /&gt;                $data = $form-&amp;gt;getValues();&lt;br /&gt;                if($data['password'] != $data['confirmPassword']){&lt;br /&gt;                    $this-&amp;gt;view-&amp;gt;errorMessage = &amp;quot;Password and confirm password don't match.&amp;quot;;&lt;br /&gt;                    return;&lt;br /&gt;                }&lt;br /&gt;                if($users-&amp;gt;checkUnique($data['username'])){&lt;br /&gt;                    $this-&amp;gt;view-&amp;gt;errorMessage = &amp;quot;Name already taken. Please choose      another one.&amp;quot;;&lt;br /&gt;                    return;&lt;br /&gt;                }&lt;br /&gt;                unset($data['confirmPassword']);&lt;br /&gt;                $users-&amp;gt;insert($data);&lt;br /&gt;                $this-&amp;gt;_redirect('auth/login');&lt;br /&gt;            }&lt;br /&gt;        }&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;This action is used for signup purpose. We create instance of our model class and Registration Form. And assign form to our view template.&lt;br /&gt;Check for the post request and valid form.&lt;br /&gt;If the form is valid we get form values. Check if both the password fields don’t have same data. If they are not same we assign error message to the view template.&lt;br /&gt;Next we call our checkUnique() method of the model class. This checkUnique() method check the data in the database. If row with the posted username is already in the database it return ture, means username already exist in the database. If username found we assign error message to view telling the user to choose another username. It not we insert the data in the database. And redirect the request to login action.&lt;br /&gt;Our model class look as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class Users extends Zend_Db_Table&lt;br /&gt;{&lt;br /&gt;    protected $_name=&amp;quot;users&amp;quot;;&lt;br /&gt;    function checkUnique($username)&lt;br /&gt;    {&lt;br /&gt;        $select = $this-&amp;gt;_db-&amp;gt;select()&lt;br /&gt;                            -&amp;gt;from($this-&amp;gt;_name,array('username'))&lt;br /&gt;                            -&amp;gt;where('username=?',$username);&lt;br /&gt;        $result = $this-&amp;gt;getAdapter()-&amp;gt;fetchOne($select);&lt;br /&gt;        if($result){&lt;br /&gt;            return true;&lt;br /&gt;        }&lt;br /&gt;        return false;&lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;To create a template file for the signup action, place the following code in views/scripts/auth/signup.phtml&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?&lt;br /&gt;&lt;br /&gt;if(isset($this-&amp;gt;errorMessage)){&lt;br /&gt;&lt;br /&gt;            echo $this-&amp;gt;errorMessage;&lt;br /&gt;&lt;br /&gt;}?&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;h4&amp;gt;Sign up&amp;lt;/h4&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;?&lt;br /&gt;&lt;br /&gt;echo $this-&amp;gt;form;&lt;br /&gt;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;first we check for the error, if error message is set in the action we display that.&lt;br /&gt;Next we display our Registarion form.&lt;br /&gt;The last and final thing is our logout action.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;public function logoutAction()&lt;br /&gt;    {&lt;br /&gt;        $storage = new Zend_Auth_Storage_Session();&lt;br /&gt;        $storage-&amp;gt;clear();&lt;br /&gt;        $this-&amp;gt;_redirect('auth/login');&lt;br /&gt;    }&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here we create instance of Zend_Auth_Storage_Session and clear it.&lt;br /&gt;And we then redirect our request to login action.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-8190179655302555283?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/8190179655302555283/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-sign-up-and.html#comment-form' title='49 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8190179655302555283'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8190179655302555283'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-sign-up-and.html' title='Zend Framework sign up and authentication'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>49</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-8787053568587195787</id><published>2009-07-01T05:38:00.000-07:00</published><updated>2009-07-01T11:21:04.769-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Form display groups decorators example</title><content type='html'>In my previous posts I discussed creation of zend form and decorators. These features are very helpful and quite easy to use.&lt;br /&gt;However to give better look and feel to your form you will need to study Zend From display groups.&lt;br /&gt;Display groups are used to group form elements for display purposes, so they give new look and feel to your forms. The name&lt;br /&gt;of the form elements remain the same however elements in the same group are render together.&lt;br /&gt;The most common use case would be to use display groups to put your form element in different field sets.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_bn44g8iuZbQ/SktZLSvxzJI/AAAAAAAAACo/8cum91u2Q64/s1600-h/zend_form_displaygroups1.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 320px; height: 217px;" src="http://4.bp.blogspot.com/_bn44g8iuZbQ/SktZLSvxzJI/AAAAAAAAACo/8cum91u2Q64/s320/zend_form_displaygroups1.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5353470632605633682" /&gt;&lt;/a&gt;&lt;br /&gt;Your may require similar type of layout for your form in your application. It is very simple to achieve this layout. The code&lt;br /&gt;&lt;br /&gt;is given bellow.&lt;br /&gt;Before explaining the code I would like to tell you that Zend Form uses Zend_Form_ DisplayGroup class define in&lt;br /&gt;Zend/Form/DisplayGroup.php for display groups.&lt;br /&gt;This class contains all the necessary attributes and methods to handle Zend Form display groups.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;class SimpleForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;    public function __construct($options = null)&lt;br /&gt;    {&lt;br /&gt;    &lt;br /&gt;        parent::__construct($options);&lt;br /&gt;        $countryList=array('USA','UK');&lt;br /&gt;        $firstName =  $this-&amp;gt;createElement('text', 'firstName');&lt;br /&gt;        $firstName-&amp;gt;setLabel('First Name')&lt;br /&gt;                -&amp;gt;setAttrib('size',25)&lt;br /&gt;                -&amp;gt;addValidator('StringLength', false,array(3,50))&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;        &lt;br /&gt;        $lastName =  $this-&amp;gt;createElement('text', 'lastName');&lt;br /&gt;        $lastName-&amp;gt;setLabel('Last Name:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                -&amp;gt;addValidator('StringLength', false,array(3,50))&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;        &lt;br /&gt;        $address1 =  $this-&amp;gt;createElement('text', 'address1');&lt;br /&gt;        $address1-&amp;gt;setLabel('Address1:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                -&amp;gt;addValidator('StringLength', false,array(3,50))&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;        &lt;br /&gt;        $address2 =  $this-&amp;gt;createElement('text', 'address2');&lt;br /&gt;        $address2-&amp;gt;setLabel('Address2:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                -&amp;gt;addValidator('StringLength', false,array(3,50))&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(false);&lt;br /&gt;        &lt;br /&gt;        $postalCode =  $this-&amp;gt;createElement('text', 'postalCode');&lt;br /&gt;        $postalCode-&amp;gt;setLabel('Postalcode:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                -&amp;gt;addValidator('StringLength', false,array(3,15))&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(false);&lt;br /&gt;        &lt;br /&gt;        $city = $this-&amp;gt;createElement('text', 'city');&lt;br /&gt;        $city-&amp;gt;setLabel('City:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(false)&lt;br /&gt;                -&amp;gt;setAttrib('tabindex','6');&lt;br /&gt;        &lt;br /&gt;        $state = $this-&amp;gt;createElement('text', 'state');&lt;br /&gt;        $state-&amp;gt;setLabel('State:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 6)&lt;br /&gt;                -&amp;gt;setAttrib('maxlength', 2)&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(false)&lt;br /&gt;                -&amp;gt;setAttrib('tabindex','7');&lt;br /&gt;        &lt;br /&gt;        $country = $this-&amp;gt;createElement('select', 'country');&lt;br /&gt;        $country-&amp;gt;setLabel('Country:')&lt;br /&gt;                -&amp;gt;setAttrib('class','select')&lt;br /&gt;                -&amp;gt;addMultiOptions($countryList)&lt;br /&gt;                -&amp;gt;setRequired(false);&lt;br /&gt;        &lt;br /&gt;        $phone = $this-&amp;gt;createElement('text', 'phone');&lt;br /&gt;        $phone-&amp;gt;setLabel('Phone:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                -&amp;gt;setAttrib('maxlength', '25')&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;        &lt;br /&gt;        $emailAddress =  $this-&amp;gt;createElement('text', 'emailAddress');&lt;br /&gt;        $emailAddress-&amp;gt;setLabel('Email:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                -&amp;gt;addValidator('StringLength', false,array(5,50))&lt;br /&gt;                -&amp;gt;addValidator('EmailAddress')&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;                &lt;br /&gt;        $website = $this-&amp;gt;CreateElement('text','website');&lt;br /&gt;        $website-&amp;gt;setLabel(&amp;quot;Website:&amp;quot;)&lt;br /&gt;                -&amp;gt;setAttrib('size', 25);&lt;br /&gt;        &lt;br /&gt;        $userName =  $this-&amp;gt;createElement('text', 'userName');&lt;br /&gt;        $userName-&amp;gt;setLabel('Username:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                -&amp;gt;addValidator('StringLength', false,array(5,50))&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setRequired(true);&lt;br /&gt;        &lt;br /&gt;        $password =  $this-&amp;gt;createElement('password','password');&lt;br /&gt;        $password-&amp;gt;setLabel('Password:')&lt;br /&gt;                -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                -&amp;gt;addValidator('StringLength', false,array(3,50))&lt;br /&gt;                -&amp;gt;setRequired(true)&lt;br /&gt;                -&amp;gt;setValue('')&lt;br /&gt;                -&amp;gt;setIgnore(false);&lt;br /&gt;        &lt;br /&gt;        $confirmPassword =  $this-&amp;gt;createElement('password','confirmPassword');&lt;br /&gt;        $confirmPassword-&amp;gt;setLabel('Confirm Password:')&lt;br /&gt;                    -&amp;gt;setAttrib('size', 25)&lt;br /&gt;                    -&amp;gt;addValidator('StringLength', false,array(3,50))&lt;br /&gt;                    -&amp;gt;setRequired(true)&lt;br /&gt;                    -&amp;gt;setValue('')&lt;br /&gt;                    -&amp;gt;setIgnore(false);&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;addElements( array (&lt;br /&gt;        &lt;br /&gt;                            $firstName,&lt;br /&gt;                            $lastName,&lt;br /&gt;                            $address1,&lt;br /&gt;                            $address2,&lt;br /&gt;                            $postalCode,&lt;br /&gt;                            $city,&lt;br /&gt;                            $state,&lt;br /&gt;                            $country,&lt;br /&gt;                            $phone,&lt;br /&gt;                            $emailAddress,&lt;br /&gt;                            $website,&lt;br /&gt;                            $userName,&lt;br /&gt;                            $password,&lt;br /&gt;                            $confirmPassword&lt;br /&gt;                            )&lt;br /&gt;                );&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;addDisplayGroup(array(&lt;br /&gt;        &lt;br /&gt;                    'firstName',&lt;br /&gt;                    'lastName',&lt;br /&gt;                    'userName',&lt;br /&gt;                    'address1',&lt;br /&gt;                    'address2',&lt;br /&gt;                    'postalCode',&lt;br /&gt;                    'city',&lt;br /&gt;                    'state',&lt;br /&gt;                    'country',&lt;br /&gt;                    'phone'&lt;br /&gt;        &lt;br /&gt;            ),'contact',array('legend' =&amp;gt; 'Contact Information'));&lt;br /&gt;        &lt;br /&gt;        $contact = $this-&amp;gt;getDisplayGroup('contact');&lt;br /&gt;        $contact-&amp;gt;setDecorators(array(&lt;br /&gt;        &lt;br /&gt;                    'FormElements',&lt;br /&gt;                    'Fieldset',&lt;br /&gt;                    array('HtmlTag',array('tag'=&amp;gt;'div','style'=&amp;gt;'width:50%;;float:left;'))&lt;br /&gt;        ));&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;addDisplayGroup(array(&lt;br /&gt;        &lt;br /&gt;                    'password',&lt;br /&gt;                    'confirmPassword',&lt;br /&gt;        &lt;br /&gt;        ),'pass',array('legend' =&amp;gt; 'Password'));&lt;br /&gt;        &lt;br /&gt;        $pass = $this-&amp;gt;getDisplayGroup('pass');&lt;br /&gt;        $pass-&amp;gt;setDecorators(array(&lt;br /&gt;        &lt;br /&gt;                'FormElements',&lt;br /&gt;                'Fieldset',&lt;br /&gt;                array('HtmlTag',array('tag'=&amp;gt;'div','openOnly'=&amp;gt;true,'style'=&amp;gt;'width:48%;;float:right'))&lt;br /&gt;        ));&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;addDisplayGroup(array(&lt;br /&gt;        &lt;br /&gt;                'emailAddress',&lt;br /&gt;                'website',&lt;br /&gt;        &lt;br /&gt;        ),'web',array('legend' =&amp;gt; 'Web Information'));&lt;br /&gt;        &lt;br /&gt;        $web = $this-&amp;gt;getDisplayGroup('web');&lt;br /&gt;        $web-&amp;gt;setDecorators(array(&lt;br /&gt;        &lt;br /&gt;                'FormElements',&lt;br /&gt;                'Fieldset',&lt;br /&gt;                array('HtmlTag',array('tag'=&amp;gt;'div','closeOnly'=&amp;gt;true))&lt;br /&gt;        ));&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;setDecorators(array(&lt;br /&gt;                'FormElements',&lt;br /&gt;                array('HtmlTag',array('tag'=&amp;gt;'div','style'=&amp;gt;'width:98%')),&lt;br /&gt;                'Form'&lt;br /&gt;        ));&lt;br /&gt;    &lt;br /&gt;    }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The code above is very simple to explain.&lt;br /&gt;we are extending Zend_Form as usual,define our constructor and call parent class constructor. You can override init() method&lt;br /&gt;of Zend_Form and place the above code in that function.&lt;br /&gt;Next we create elements and add to the form using addElements() method.&lt;br /&gt;Next lines are important. beacuse we are define our display groups and decorators in these lines.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;addDisplayGroup(array(&lt;br /&gt;        &lt;br /&gt;                    'firstName',&lt;br /&gt;                    'lastName',&lt;br /&gt;                    'userName',&lt;br /&gt;                    'address1',&lt;br /&gt;                    'address2',&lt;br /&gt;                    'postalCode',&lt;br /&gt;                    'city',&lt;br /&gt;                    'state',&lt;br /&gt;                    'country',&lt;br /&gt;                    'phone'&lt;br /&gt;        &lt;br /&gt;            ),'contact',array('legend' =&amp;gt; 'Contact Information'));&lt;br /&gt;        &lt;br /&gt;        $contact = $this-&amp;gt;getDisplayGroup('contact');&lt;br /&gt;        $contact-&amp;gt;setDecorators(array(&lt;br /&gt;        &lt;br /&gt;                    'FormElements',&lt;br /&gt;                    'Fieldset',&lt;br /&gt;                    array('HtmlTag',array('tag'=&amp;gt;'div','style'=&amp;gt;'width:50%;;float:left;'))&lt;br /&gt;        ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Zend_Form setDisplayGroup() method take three arguments i.e. array of elements, name of display group and optional parameters&lt;br /&gt;array.&lt;br /&gt;we are giving our first display group a name “contact”.&lt;br /&gt;then we get reference of display group and set its decorators using setDecorators method of the DisplayGroup class.&lt;br /&gt;thats is. enjoy.&lt;br /&gt;if you need extra information, post your questions.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-8787053568587195787?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/8787053568587195787/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-form-display-groups-decorators.html#comment-form' title='14 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8787053568587195787'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8787053568587195787'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-form-display-groups-decorators.html' title='Zend Form display groups decorators example'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_bn44g8iuZbQ/SktZLSvxzJI/AAAAAAAAACo/8cum91u2Q64/s72-c/zend_form_displaygroups1.jpg' height='72' width='72'/><thr:total>14</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-7885632324333471386</id><published>2009-07-01T05:12:00.000-07:00</published><updated>2009-07-01T11:21:36.848-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='JQuery'/><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Framework and JQuery: JQuery Date Picker</title><content type='html'>Nearly two months back I used dojo calendar in my application. Although dojo has extremely large library and provide very nice widgets like number spinner, horizontal scroller and more importantly gird, however the current calendar available is not good looking and provide only basic functionality. We were using JACS calendar before using dojo calendar in our application.&lt;br /&gt;&lt;br /&gt;After working for a bit of time with dojo calendar we feel that we need JACS type calendar. We were looking for the latest dojo release for getting calendar with more functionality.&lt;br /&gt;&lt;br /&gt;Today I find JQuery Date picker, which is similar to the JACS. As Zend Framework latest version now provide JQuery View helper and Form elements, so I decided to write article on it, so that developers using JQuery may find some useful information.&lt;br /&gt;&lt;br /&gt;So lets look how to develop a nice and cool JQuery date picker.&lt;br /&gt;&lt;br /&gt;At the end of this article we will have a calendar like the following.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_bn44g8iuZbQ/SktS-RBBG0I/AAAAAAAAACg/ZQCJ6zCYx-E/s1600-h/zend_jquery_datepicker.jpg"&gt;&lt;img style="cursor:pointer; cursor:hand;width: 306px; height: 228px;" src="http://4.bp.blogspot.com/_bn44g8iuZbQ/SktS-RBBG0I/AAAAAAAAACg/ZQCJ6zCYx-E/s320/zend_jquery_datepicker.jpg" border="0" alt=""id="BLOGGER_PHOTO_ID_5353463811733003074" /&gt;&lt;/a&gt;&lt;br /&gt;First of all download the latest version of Zend framework and placed “ZendX” folder in the library/ directory. The same library/ directory where your Zend folder reside.&lt;br /&gt;&lt;br /&gt;Now to create the above calendar we will first need to write the following code in our bootstrap file.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$view= new Zend_View();&lt;br /&gt;&lt;br /&gt;$viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();&lt;br /&gt;&lt;br /&gt;$view-&amp;gt;addHelperPath(&amp;#8217;ZendX/JQuery/View/Helper/&amp;#8217;, &amp;#8216;ZendX_JQuery_View_Helper&amp;#8217;);&lt;br /&gt;&lt;br /&gt;$viewRenderer-&amp;gt;setView($view);&lt;br /&gt;&lt;br /&gt;Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here we are initializing our Zend_View object (don’t initialize it if you have already done in bootstrap file).&lt;br /&gt;&lt;br /&gt;Next we initialize Zend_Cotroller_Action_Helper_ViewRendere object and add helper path.&lt;br /&gt;&lt;br /&gt;At the end we set view to viewRenderer and add helper to the Zend_Controller_Action_HelperBroker.&lt;br /&gt;&lt;br /&gt;That’s it we have now setup our environment.&lt;br /&gt;&lt;br /&gt;Next we enable JQuery in our layout file as&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;jQuery()-&amp;gt;setLocalPath('http://localhost/zend/js/jquery/jquery-1.2.6.js')&lt;br /&gt;&lt;br /&gt;               -&amp;gt;addStylesheet('http://localhost/zend/js/jquery/themes/ui.datepicker.css');&lt;br /&gt;echo $this-&amp;gt;jQuery();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;we are setting path to the jquery js file and datepicker css file.&lt;br /&gt;Next in the view template file&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;Pick your Date: &amp;lt;?= $this-&amp;gt;datePicker(&amp;quot;dp1&amp;quot;,&lt;br /&gt;                            '',&lt;br /&gt;                        array('defaultDate' =&amp;gt; date('Y/m/d', time()))); ?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;That’s it. Nice and beautiful JQuery data picker.&lt;br /&gt;&lt;br /&gt;Cheers.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-7885632324333471386?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/7885632324333471386/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-and-jquery-jquery-date.html#comment-form' title='19 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7885632324333471386'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/7885632324333471386'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-and-jquery-jquery-date.html' title='Zend Framework and JQuery: JQuery Date Picker'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://4.bp.blogspot.com/_bn44g8iuZbQ/SktS-RBBG0I/AAAAAAAAACg/ZQCJ6zCYx-E/s72-c/zend_jquery_datepicker.jpg' height='72' width='72'/><thr:total>19</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-624842641447855187</id><published>2009-07-01T05:05:00.000-07:00</published><updated>2009-07-01T11:21:54.547-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Framework: Layout and views (two step view)</title><content type='html'>In this article I’m going to discuss layout and views and will give a practical example.&lt;br /&gt;&lt;br /&gt;You may have heard of two step view.&lt;br /&gt;&lt;br /&gt;The term two step view is used when we use layout and view templates for making our page look and feel.&lt;br /&gt;&lt;br /&gt;Mostly you will need header, menu and footer same for the entire web application, only contents in the center of the page changes. So if this is the case you can get benefits out of two step views.&lt;br /&gt;&lt;br /&gt;Create a layout containing header, menus and footer etc and view will have the contents relevant that specific page.&lt;br /&gt;&lt;br /&gt;To implement two step view  in Zend framework you will need to make some configuration in bootstrap file.&lt;br /&gt;&lt;br /&gt;Add the following lines to your bootstrap file.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$options = array(&lt;br /&gt;    'layout'     =&amp;gt; 'layout_name',&lt;br /&gt;    'layoutPath' =&amp;gt; '/path/to/layouts',&lt;br /&gt;);&lt;br /&gt;$layout = Zend_Layout::startMvc($options);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Keep in mind two things.&lt;br /&gt;1.    Specify correct layout_name.&lt;br /&gt;2.    Path to the layout file must be correct.&lt;br /&gt;I usually prefer to create my layout directory in scripts directory under application/views.&lt;br /&gt; &lt;br /&gt;If you create layout.phtml in your layouts directory you will need to define it as follows.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;?php&lt;br /&gt;        include &amp;quot;header.phtml&amp;quot;;&lt;br /&gt;        &lt;br /&gt;?&amp;gt;&lt;br /&gt;// view contents goes here.&lt;br /&gt;&amp;lt;?php&lt;br /&gt;        &lt;br /&gt;        &amp;lt;?=$this-&amp;gt;layout()-&amp;gt;content?&amp;gt;&lt;br /&gt; &lt;br /&gt;?&amp;gt;&lt;br /&gt;// footer goes here.&lt;br /&gt;&amp;lt;?php&lt;br /&gt;        include &amp;quot;footer.phtml&amp;quot;&lt;br /&gt;?&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Now whatever request (controller/action) you made to your page, header and footer will be included in the response.&lt;br /&gt;&lt;br /&gt;There may be cases (in some of your actions) where you don’t want your header and footer be appeared in the look and feel.&lt;br /&gt;&lt;br /&gt;So write in those actions, the following line of code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;_helper-&amp;gt;layout-&amp;gt;disableLayout();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;After including this line in your action, only the view contents will appear. It mean the contents in the header and footer will not be served.&lt;br /&gt;&lt;br /&gt;Some time you need to execute only action code and redirect your request to another action instead of showing anything.&lt;br /&gt;&lt;br /&gt;Write the following code in this case&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    $this-&amp;gt;_helper-&amp;gt;layout-&amp;gt;disableLayout();&lt;br /&gt;&lt;br /&gt;    $this-&amp;gt;_helper-&amp;gt;viewRenderer-&amp;gt;setNoRender();&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Another very important thing is when you call a specific action, Zend Framework render a template file with the name similar to the action name. for example if you request view action, Zend will look for view.phtml file in the specific template directory.&lt;br /&gt;&lt;br /&gt;If you want to render other then the default template, view.phtml in the above example. Write the following in your action.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$this-&amp;gt;render(&amp;#8217;thanks&amp;#8217;);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-624842641447855187?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/624842641447855187/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-layout-and-views-two.html#comment-form' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/624842641447855187'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/624842641447855187'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-framework-layout-and-views-two.html' title='Zend Framework: Layout and views (two step view)'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-5524468557065193113</id><published>2009-07-01T04:00:00.000-07:00</published><updated>2009-07-01T11:22:18.606-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Pagination example</title><content type='html'>Paginator component is available with Zend Framework v1.6. This component wasn’t available in v1.5. I appreciate Zend for provide such a nice component for pagination. This component, like other component, is so loosely coupled that you can use it wherever you want without worrying about any other component at all.&lt;br /&gt;If you have already created pages and you want to apply pagination to them, it would not be a big deal.&lt;br /&gt;Pagination is three step process.&lt;br /&gt;&lt;br /&gt;1. you will need to create template file. In template file you can specify layout of your pagination. i.e. how your first, previous, next and last etc will be displayed.&lt;br /&gt;&lt;br /&gt;2. instantiate your pagination class in the controller and pass data source- data source can be an array, values fetched form the database etc.&lt;br /&gt;&lt;br /&gt;3. make some change in your template file, where you are showing your records.&lt;br /&gt;Lets have a simple example.&lt;br /&gt;First create a template file pagination.phtml in your “/application/view/script/” folder and place the following code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;div class=&amp;quot;pagination&amp;quot; style=&amp;quot;width:100%&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;div style=&amp;quot;float:left;width:28%&amp;quot;&amp;gt;&lt;br /&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt;    &amp;lt;div style=&amp;quot;float:right;width:70%;&amp;quot;&amp;gt;&lt;br /&gt;        &amp;lt;!-- First page link --&amp;gt;&lt;br /&gt;        &amp;lt;?php if (isset($this-&amp;gt;previous)): ?&amp;gt;&lt;br /&gt;              &amp;lt;a href=&amp;quot;&amp;lt;?= $this-&amp;gt;url(array('page' =&amp;gt; $this-&amp;gt;first)); ?&amp;gt;&amp;quot;&amp;gt;Start&amp;lt;/a&amp;gt; &amp;#124;&lt;br /&gt;        &amp;lt;?php else: ?&amp;gt;&lt;br /&gt;                &amp;lt;span class=&amp;quot;disabled&amp;quot;&amp;gt;Start&amp;lt;/span&amp;gt; &amp;#124;&lt;br /&gt;        &amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;    &lt;br /&gt;        &amp;lt;!-- Previous page link --&amp;gt;&lt;br /&gt;    &lt;br /&gt;        &amp;lt;?php if (isset($this-&amp;gt;previous)): ?&amp;gt;&lt;br /&gt;              &amp;lt;a href=&amp;quot;&amp;lt;?= $this-&amp;gt;url(array('page' =&amp;gt; $this-&amp;gt;previous)); ?&amp;gt;&amp;quot;&amp;gt;&amp;amp;lt; Previous&amp;lt;/a&amp;gt; &amp;#124;&lt;br /&gt;        &amp;lt;?php else: ?&amp;gt;&lt;br /&gt;            &amp;lt;span class=&amp;quot;disabled&amp;quot;&amp;gt;&amp;amp;lt; Previous&amp;lt;/span&amp;gt; &amp;#124;&lt;br /&gt;        &amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;        &amp;lt;!-- Numbered page links --&amp;gt;&lt;br /&gt;        &amp;lt;?php foreach ($this-&amp;gt;pagesInRange as $page): ?&amp;gt;&lt;br /&gt;            &amp;lt;?php if ($page != $this-&amp;gt;current): ?&amp;gt;&lt;br /&gt;                &amp;lt;a href=&amp;quot;&amp;lt;?= $this-&amp;gt;url(array('page' =&amp;gt; $page)); ?&amp;gt;&amp;quot;&amp;gt;&amp;lt;?= $page; ?&amp;gt;&amp;lt;/a&amp;gt;&lt;br /&gt;            &amp;lt;?php else: ?&amp;gt;&lt;br /&gt;                &amp;lt;?= $page; ?&amp;gt;&lt;br /&gt;            &amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;        &amp;lt;?php endforeach; ?&amp;gt;&lt;br /&gt;        &amp;lt;!-- Next page link --&amp;gt;&lt;br /&gt;        &amp;lt;?php if (isset($this-&amp;gt;next)): ?&amp;gt;&lt;br /&gt;              &amp;#124; &amp;lt;a href=&amp;quot;&amp;lt;?= $this-&amp;gt;url(array('page' =&amp;gt; $this-&amp;gt;next)); ?&amp;gt;&amp;quot;&amp;gt;Next &amp;amp;gt;&amp;lt;/a&amp;gt; &amp;#124;&lt;br /&gt;        &amp;lt;?php else: ?&amp;gt;&lt;br /&gt;            &amp;#124; &amp;lt;span class=&amp;quot;disabled&amp;quot;&amp;gt;Next &amp;amp;gt;&amp;lt;/span&amp;gt; &amp;#124;&lt;br /&gt;        &amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;        &amp;lt;!-- Last page link --&amp;gt;&lt;br /&gt;        &amp;lt;?php if (isset($this-&amp;gt;next)): ?&amp;gt;&lt;br /&gt;              &amp;lt;a href=&amp;quot;&amp;lt;?= $this-&amp;gt;url(array('page' =&amp;gt; $this-&amp;gt;last)); ?&amp;gt;&amp;quot;&amp;gt;End&amp;lt;/a&amp;gt;&lt;br /&gt;        &amp;lt;?php else: ?&amp;gt;&lt;br /&gt;            &amp;lt;span class=&amp;quot;disabled&amp;quot;&amp;gt;End&amp;lt;/span&amp;gt;&lt;br /&gt;        &amp;lt;?php endif; ?&amp;gt;&lt;br /&gt;        &amp;amp;nbsp; Page &amp;lt;?= $this-&amp;gt;current; ?&amp;gt; of &amp;lt;?= $this-&amp;gt;last; ?&amp;gt;&lt;br /&gt;    &amp;lt;/div&amp;gt;&lt;br /&gt; &amp;lt;/div&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The code above is self explanatory. We are creating links for the pagination.&lt;br /&gt;&lt;br /&gt;Next add the following code in your controller.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$sql = 'SELECT * FROM table_name ';&lt;br /&gt;    $result = $db-&amp;gt;fetchAll($sql);&lt;br /&gt;    $page=$this-&amp;gt;_getParam('page',1);&lt;br /&gt;    $paginator = Zend_Paginator::factory($result);&lt;br /&gt;    $paginator-&amp;gt;setItemCountPerPage(10));&lt;br /&gt;    $paginator-&amp;gt;setCurrentPageNumber($page);&lt;br /&gt;&lt;br /&gt;    $this-&amp;gt;view-&amp;gt;paginator=$paginator;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In the code above we first fetch records from our database. Then instantiate our paginator by writing&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;$paginator = Zend_Paginator::factory($result);&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;And pass it results we have fatched.&lt;br /&gt;We then set number of items per page and current page. On our first visit $page will have value 1.&lt;br /&gt;At the end we assign this paginator to our view template.&lt;br /&gt;And now in view template add the following code&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;foreach($this-&amp;gt;paginator as $record)&lt;br /&gt;    {&lt;br /&gt;        echo $record['firstname'].'\n';&lt;br /&gt;        echo $record['lastname']. '\n'&lt;br /&gt;        ...&lt;br /&gt;        ...&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &amp;lt;?= $this-&amp;gt;paginationControl($this-&amp;gt;paginator, 'Sliding', 'pagination.phtml'); ?&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;We are applying foreach loop to our paginator and echo our records. I assume that you have fistname, lastname columns in your table where you are fetching records form.Last line is compulsory. you need to call the paginator contorller and give it the $paginator, style of the pagination and the file name of the pagination template.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-5524468557065193113?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/5524468557065193113/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-pagination-example.html#comment-form' title='41 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/5524468557065193113'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/5524468557065193113'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-pagination-example.html' title='Zend Pagination example'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>41</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-6056580100761934051</id><published>2009-07-01T01:08:00.000-07:00</published><updated>2009-07-01T11:22:45.844-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Form Decorators</title><content type='html'>I’d felt a lot of pain when I first used Zend_Form. The reason was that I wasn’t able to layout form elements the way I wanted them to be. Zend was rendering elements in dt and dd whilst I was looking forward to place them in row and cells.&lt;br /&gt;In short I wasn’t aware of Zend_Form decorators in the beginning and when I studied them for some time I felt uncomfortable using them.&lt;br /&gt;So I decided to use html forms in my phtml files-template file. Though by doing so I achieved the desired layout however I missed entire facilities/functionalities that Zend_Form component provide us such as validation, filtering, dispaying error messages and so on.&lt;br /&gt;When I first created form with Zend_Form component I was served with layout like the following.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_bn44g8iuZbQ/SksZ2WK8K2I/AAAAAAAAACA/2Ub2ow7MuSQ/s1600-h/login1.jpg"&gt;&lt;img style="cursor: pointer; width: 209px; height: 152px;" src="http://3.bp.blogspot.com/_bn44g8iuZbQ/SksZ2WK8K2I/AAAAAAAAACA/2Ub2ow7MuSQ/s320/login1.jpg" alt="" id="BLOGGER_PHOTO_ID_5353401003515063138" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Label on the top of the text/ password element.&lt;br /&gt;&lt;br /&gt;This is because Zend Framework render form label in "dt" tag and text/password form element in "dt","dd" tag and put entire form element in "dl" tag by default.&lt;br /&gt;&lt;br /&gt;Code rendered was&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;form method="post" action=""&amp;gt;&lt;br /&gt;&amp;lt;dl class="zend_form"&amp;gt;&lt;br /&gt;&amp;lt;dt&amp;gt;&amp;lt;label for="agencyName" class="optional"&amp;gt;User Name:&amp;lt;/label&amp;gt;&amp;lt;/dt&amp;gt;&lt;br /&gt;&amp;lt;dd&amp;gt;&lt;br /&gt;       &amp;lt;input type="text" name="agencyName" id="agencyName" value=""&amp;gt;&lt;br /&gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;&amp;lt;dt&amp;gt;&amp;lt;label for="advertiserName" class="optional"&amp;gt;Password&amp;lt;/label&amp;gt;&amp;lt;/dt&amp;gt;&lt;br /&gt;&amp;lt;dd&amp;gt;&lt;br /&gt;       &amp;lt;input type="text" name="advertiserName" id="advertiserName" value=""&amp;gt;&lt;br /&gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;&amp;lt;dt&amp;gt;&amp;amp;nbsp;&amp;lt;/dt&amp;gt;&lt;br /&gt;&amp;lt;dd&amp;gt;&lt;br /&gt;       &amp;lt;input type="submit" name="submit" id="submit" value="Login"&amp;gt;&lt;br /&gt;&amp;lt;/dd&amp;gt;&lt;br /&gt;&amp;lt;dl&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This was not the layout I was looking for. I was looking for&lt;br /&gt;layout like the following.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://2.bp.blogspot.com/_bn44g8iuZbQ/SksamTzLGwI/AAAAAAAAACI/Rf8ngFFje44/s1600-h/login21.jpg"&gt;&lt;img style="cursor: pointer; width: 255px; height: 103px;" src="http://2.bp.blogspot.com/_bn44g8iuZbQ/SksamTzLGwI/AAAAAAAAACI/Rf8ngFFje44/s320/login21.jpg" alt="" id="BLOGGER_PHOTO_ID_5353401827512228610" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;To create form as above one need to put label and individual form element in "td" tag, put that "td" tag in "tr" tag and put all these in "table" tag. E.g&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;form action="" method="post"&amp;gt;&lt;br /&gt;   &amp;lt;table&amp;gt;&lt;br /&gt;       &amp;lt;tr&amp;gt;&lt;br /&gt;           &amp;lt;td&amp;gt;&amp;lt;label for="username" class="optional"&amp;gt;User Name:&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;           &amp;lt;td&amp;gt;&amp;lt;input type="text" name="username"&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;       &amp;lt;/tr&amp;gt;&lt;br /&gt;       &amp;lt;tr&amp;gt;&lt;br /&gt;           &amp;lt;td&amp;gt;&amp;lt;label for="password" class="optional"&amp;gt;Password&amp;lt;/label&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;           &amp;lt;td&amp;gt;&amp;lt;input type="password" name="password"&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;       &amp;lt;/tr&amp;gt;&lt;br /&gt;       &amp;lt;tr&amp;gt;&lt;br /&gt;           &amp;lt;td colspan="2" align="center"&amp;gt;&lt;br /&gt;           &amp;lt;input type="submit" name="submit" id="submit" value="Login"&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;       &amp;lt;/tr&amp;gt;&lt;br /&gt;   &amp;lt;/table&amp;gt;&lt;br /&gt;&amp;lt;/form&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Zend form decorators can be used to create above form.&lt;br /&gt;&lt;br /&gt;If you are beginner or have little experience working with zend, you may be facing difficulties in rendering Form using Zend_Form the way you want.&lt;br /&gt;&lt;br /&gt;In this post I am providing indepth and comprehensive study of how to use Zend_Form_Decorators.&lt;br /&gt;&lt;br /&gt;So let’s get started.&lt;br /&gt;&lt;br /&gt;Although in the beginning you may find it difficult to use Zend_Form decorators, however once you get used to it and understand the basics, you will find these quite easy, helpful and interesting.&lt;br /&gt;&lt;br /&gt;To create the login form in the figure 2. you will need the following code&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;class forms_LoginForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;   public function __construct($option=null)&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;       parent::__construct($option);&lt;br /&gt;  &lt;br /&gt;       $this-&amp;gt;setMethod('post');&lt;br /&gt;  &lt;br /&gt;       $username=$this-&amp;gt;CreateElement('text','username')&lt;br /&gt;  &lt;br /&gt;                       -&amp;gt;setLabel('User Name:');&lt;br /&gt;  &lt;br /&gt;       $username-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;                   'ViewHelper',&lt;br /&gt;                   'Description',&lt;br /&gt;                   'Errors',&lt;br /&gt;                   array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;                   array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;                   array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;  &lt;br /&gt;           ));&lt;br /&gt;  &lt;br /&gt;       $password=$this-&amp;gt;CreateElement('text','password')&lt;br /&gt;  &lt;br /&gt;                       -&amp;gt;setLabel('Password');&lt;br /&gt;  &lt;br /&gt;       $password-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;                   'ViewHelper',&lt;br /&gt;                   'Description',&lt;br /&gt;                   'Errors',&lt;br /&gt;                   array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;                   array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;                   array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $submit=$this-&amp;gt;CreateElement('submit','submit')&lt;br /&gt;  &lt;br /&gt;                       -&amp;gt;setLabel('Login');&lt;br /&gt;  &lt;br /&gt;       $submit-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               'Description',&lt;br /&gt;               'Errors', array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td',&lt;br /&gt;               'colspan'=&amp;gt;'2','align'=&amp;gt;'center')),&lt;br /&gt;               array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $this-&amp;gt;addElements(array(&lt;br /&gt;  &lt;br /&gt;               $username,&lt;br /&gt;               $password,&lt;br /&gt;               $submit&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $this-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'FormElements',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'table')),&lt;br /&gt;               'Form'&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Explanation:&lt;br /&gt;&lt;br /&gt;First we extend our form from Zend_From and define our constructor. It is necessary to call parent class constructor before defining anything in your own constructor-by doing so our form will inherit all the functionality of Zend_Form.&lt;br /&gt;&lt;br /&gt;After calling parent constructor we set our form method by simply $this-&gt;setMethod(‘post’).&lt;br /&gt;&lt;br /&gt;Next we create text element and set its label.&lt;br /&gt;&lt;br /&gt;The lines after setting label of the form are important because these lines give new look to our form. The code is quite simple. We call setDecorators() method of the form to override the default decorators behavior of the form.&lt;br /&gt;The code&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$username-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;                   'ViewHelper',&lt;br /&gt;                   'Description',&lt;br /&gt;                   'Errors',&lt;br /&gt;                   array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;                   array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;                   array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;  &lt;br /&gt;           ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;is very simple. We are skipping “ViewHelper”, “Description” and “Errors” for now. We will explain it some other time. We can define our decorators for these things as well if we need in future. However leave it as these are for now.&lt;br /&gt;&lt;br /&gt;After “Errors” we define array which tell Zend to override the default decorators of&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;&amp;lt;input name=&amp;quot;&amp;#8221;username&amp;#8221;&amp;quot; type=&amp;quot;&amp;#8221;text&amp;#8221;&amp;quot;&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;. By doing so zend will wrap "input" tag in .&lt;br /&gt;&lt;br /&gt;Next array define tag for label and put label in td tag as&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;td&amp;gt;&amp;lt;label ..&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;.&lt;br /&gt;&lt;br /&gt;Next array define tag for the row of the form. This wrap&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;label ..&amp;gt;and &amp;lt;input&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;in tr tag. The above code will create&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;tr&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;td&amp;gt;User Name:&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;td&amp;gt;&amp;lt;input type=”text” name=”username”&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/tr&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;However defining decorators for the submit button we have change the code a lit bit.&lt;br /&gt;&lt;br /&gt;As label is appearing on the button so we don’t need to define decorator for the label. By leaving decorator for label undefined, it means zend will use its default decorator for the label of the submit button.&lt;br /&gt;&lt;br /&gt;And as we want to put button at the center of the row, so we have defined&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td',&lt;br /&gt;                                               'colspan'=&amp;gt;'2','align'=&amp;gt;'center')),&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This will create html as&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;td colspan=”2” align=”center”&amp;gt;&amp;lt;input type=”submit” ….&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Next we add elements to form as&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$this-&amp;gt;addElements(array(&lt;br /&gt;  &lt;br /&gt;               $username,&lt;br /&gt;               $password,&lt;br /&gt;               $submit&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;At the end we define decorators for the form-to wrap form elements in the html tag.&lt;br /&gt;&lt;br /&gt;I have already said that zend wrap entire element in "dl" tag.&lt;br /&gt;&lt;br /&gt;As we have wrap element in the "tg" and "tr" tag properly. So we need to wrap these "td" and "tr"’ in the "table" tag. To do so we have defined&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$this-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'FormElements',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'table')),&lt;br /&gt;               'Form'&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This code will wrap all "tr" in "table" tag.&lt;br /&gt;&lt;br /&gt;Although this form is simple and contain only two fields however you can create very large form by following this procedure.&lt;br /&gt;&lt;br /&gt;Next I going to create a form that may help lot of souls. First see the following form.&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_bn44g8iuZbQ/Sksf3xpcNzI/AAAAAAAAACQ/ozyf01Zo0fw/s1600-h/login3.jpg"&gt;&lt;img style="cursor: pointer; width: 300px; height: 28px;" src="http://1.bp.blogspot.com/_bn44g8iuZbQ/Sksf3xpcNzI/AAAAAAAAACQ/ozyf01Zo0fw/s320/login3.jpg" alt="" id="BLOGGER_PHOTO_ID_5353407625140385586" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;You can clearly see we have put all the form elements in the single row.&lt;br /&gt;&lt;br /&gt;The html of the above form is&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;&amp;lt;table&amp;gt;&lt;br /&gt;   &amp;lt;tr&amp;gt;&lt;br /&gt;       &amp;lt;td&amp;gt;&lt;br /&gt;              &amp;lt;label for="username" class="optional"&amp;gt;User Name:&amp;lt;/label&amp;gt;&lt;br /&gt;       &amp;lt;/td&amp;gt;&lt;br /&gt;       &amp;lt;td&amp;gt;&amp;lt;input type=”text” name=”username”&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;       &amp;lt;td&amp;gt;&lt;br /&gt;              &amp;lt;label for="password" class="optional"&amp;gt;Password&amp;lt;/label&amp;gt;&lt;br /&gt;       &amp;lt;/td&amp;gt;&lt;br /&gt;       &amp;lt;td&amp;gt;&amp;lt;input type=”password” name=”password”&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;       &amp;lt;td align="center"&amp;gt;&lt;br /&gt;       &amp;lt;input type="submit" name="submit" id="submit" value="Login"&amp;gt;&amp;lt;/td&amp;gt;&lt;br /&gt;   &amp;lt;/tr&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;/table&amp;gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You can clearly see that we have wrapped the elements in  tags and then wrap those "td" tags in single "tr" tag and then "table" . To create the above form we will make very little changes in our code above.&lt;br /&gt;&lt;br /&gt;The new code would be&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;class forms_LoginForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;   public function __construct($option=null)&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;       parent::__construct($option);&lt;br /&gt;  &lt;br /&gt;       $this-&amp;gt;setMethod('post');&lt;br /&gt;  &lt;br /&gt;       $username=$this-&amp;gt;CreateElement('text','username')&lt;br /&gt;  &lt;br /&gt;                       -&amp;gt;setLabel('User Name:');&lt;br /&gt;  &lt;br /&gt;       $username-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               'Description',&lt;br /&gt;               'Errors',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr', 'openOnly'=&amp;gt;true))&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $password=$this-&amp;gt;CreateElement('text','password')&lt;br /&gt;  &lt;br /&gt;                           -&amp;gt;setLabel('Password');&lt;br /&gt;  &lt;br /&gt;       $password-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               'Description',&lt;br /&gt;               'Errors',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $submit=$this-&amp;gt;CreateElement('submit','submit')&lt;br /&gt;  &lt;br /&gt;                   -&amp;gt;setLabel('Login');&lt;br /&gt;  &lt;br /&gt;       $submit-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               'Description',&lt;br /&gt;               'Errors', array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td',&lt;br /&gt;               'colspan'=&amp;gt;'2','align'=&amp;gt;'center')),&lt;br /&gt;               array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr', 'closeOnly'=&amp;gt;'true'))&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $this-&amp;gt;addElements(array(&lt;br /&gt;  &lt;br /&gt;               $username,&lt;br /&gt;               $password,&lt;br /&gt;               $submit&lt;br /&gt;      &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $this-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'FormElements',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'table')),&lt;br /&gt;               'Form'&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;You can see we done very minor changes in our form.&lt;br /&gt;&lt;br /&gt;In the first element “username” setDecorators() we have changed our array as&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$username-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               'Description',&lt;br /&gt;               'Errors',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr', 'openOnly'=&amp;gt;true))&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;The only changes are in the last line of the array. We have now set ‘openOnly’ =&gt; true for the “row”. It means that we are wrapping elements of username in , however we are putting  but opening it only- tag would not be closed when Zend will render this element.&lt;br /&gt;&lt;br /&gt;Next&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$password-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               'Description',&lt;br /&gt;               'Errors',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here we have defined only two arrays -third one is missing. The reason is we are wrapping elements in the "td" tag putting nothing for the row.&lt;br /&gt;&lt;br /&gt;At the final change are made in the submit element setDecorators() method call as&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$submit-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               'Description',&lt;br /&gt;               'Errors', array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td',&lt;br /&gt;               'colspan'=&amp;gt;'2','align'=&amp;gt;'center')),&lt;br /&gt;               array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr', 'closeOnly'=&amp;gt;'true'))&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Here also we have made changes in the last line-array(array(‘row’)…..). we have defined ‘closeOnly’ =&gt; ‘true’. This will close the  tag opened in the first element setDecorators() section.&lt;br /&gt;&lt;br /&gt;The rest of the code is same.&lt;br /&gt;The rest of the code is same.&lt;br /&gt;&lt;br /&gt;In almost all the websites where you find form will compulsory field indicate those fields either by placing text or image next to that field.&lt;br /&gt;&lt;br /&gt;Zend_Form setDescription() can help you out and give you an easy way to achieve this goal. Look at the following form.&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://4.bp.blogspot.com/_bn44g8iuZbQ/Sks1iUD1qlI/AAAAAAAAACY/QJU-BiU2KPU/s1600-h/login4.jpg"&gt;&lt;img style="cursor: pointer; width: 267px; height: 122px;" src="http://4.bp.blogspot.com/_bn44g8iuZbQ/Sks1iUD1qlI/AAAAAAAAACY/QJU-BiU2KPU/s320/login4.jpg" alt="" id="BLOGGER_PHOTO_ID_5353431445676599890" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;In the form above we have placed image next to our username field to tell the user that username is compulsory field.&lt;br /&gt;&lt;br /&gt;To achieve this you will need to do very little changes in your previous form.&lt;br /&gt;&lt;br /&gt;Code to create the above form is&lt;br /&gt;&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;class forms_LoginForm extends Zend_Form&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;   public function __construct($option=null)&lt;br /&gt;   {&lt;br /&gt;&lt;br /&gt;       parent::__construct($option);&lt;br /&gt;  &lt;br /&gt;       $this-&amp;gt;setMethod('post');&lt;br /&gt;  &lt;br /&gt;       $email    =    $this-&amp;gt;CreateElement('text','username')&lt;br /&gt;  &lt;br /&gt;                   -&amp;gt;setLabel('User Name:')&lt;br /&gt;  &lt;br /&gt;                   -&amp;gt;setDescription('path/to/image');&lt;br /&gt;  &lt;br /&gt;       $email-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               array('Description',array('tag'=&amp;gt;'','escape'=&amp;gt;false)),&lt;br /&gt;               'Errors',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;          &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $password=$this-&amp;gt;CreateElement('text','password')&lt;br /&gt;  &lt;br /&gt;                       -&amp;gt;setLabel('Password')&lt;br /&gt;                       -&amp;gt;setDescription('path/to/image');&lt;br /&gt;  &lt;br /&gt;       $password-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               array('Description',array('tag'=&amp;gt;'','escape'=&amp;gt;false)),&lt;br /&gt;               'Errors',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $submit=$this-&amp;gt;CreateElement('submit','submit')&lt;br /&gt;  &lt;br /&gt;                       -&amp;gt;setLabel('Login');&lt;br /&gt;  &lt;br /&gt;       $submit-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;                   'ViewHelper',&lt;br /&gt;                   'Description',&lt;br /&gt;                   'Errors', array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td',&lt;br /&gt;                   'colspan'=&amp;gt;'2','align'=&amp;gt;'center')),&lt;br /&gt;                   array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;  &lt;br /&gt;       $this-&amp;gt;addElements(array(&lt;br /&gt;  &lt;br /&gt;                       $username,&lt;br /&gt;                       $password,&lt;br /&gt;                       $submit&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;      &lt;br /&gt;       $this-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'FormElements',&lt;br /&gt;          &lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'table')),&lt;br /&gt;          &lt;br /&gt;               'Form'&lt;br /&gt;  &lt;br /&gt;       ));&lt;br /&gt;&lt;br /&gt;   }&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;If you compare the first form and this form code, you will see we have done very minor changes.  If you compare this for with the first one, you will easily find the changes. However I will define these change for the beginners.&lt;br /&gt;&lt;br /&gt;First we have added setDescription() method to our email and password elements of the form. This will add image as a description, however by default Zend will render description at the next row of the email as well as password fields. To put these images will need to define decorators for it. The only changes we will need to do in the setDecorators() methods are&lt;br /&gt;Array(‘Description’,array(‘tag’=&gt;’’,’escape’=&gt;false)) at the place of “Description”. Look at the following code.&lt;br /&gt;&lt;pre style="border: 1px dashed rgb(153, 153, 153); padding: 5px; overflow: auto; font-family: Andale Mono,Lucida Console,Monaco,fixed,monospace; color: rgb(0, 0, 0); background-color: rgb(238, 238, 238); font-size: 12px; line-height: 14px; width: 100%;"&gt;&lt;code&gt;$email-&amp;gt;setDecorators(array(&lt;br /&gt;  &lt;br /&gt;               'ViewHelper',&lt;br /&gt;               array('Description',array('tag'=&amp;gt;'','escape'=&amp;gt;false)),&lt;br /&gt;               'Errors',&lt;br /&gt;               array(array('data'=&amp;gt;'HtmlTag'), array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array('Label', array('tag' =&amp;gt; 'td')),&lt;br /&gt;               array(array('row'=&amp;gt;'HtmlTag'),array('tag'=&amp;gt;'tr'))&lt;br /&gt;          &lt;br /&gt;       ));&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;you can clearly see these changes in line 3. we have defined decorators for the description of the form element.&lt;/dl&gt;&lt;/dd&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-6056580100761934051?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/6056580100761934051/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-form-decorators.html#comment-form' title='46 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6056580100761934051'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6056580100761934051'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/07/zend-form-decorators.html' title='Zend Form Decorators'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_bn44g8iuZbQ/SksZ2WK8K2I/AAAAAAAAACA/2Ub2ow7MuSQ/s72-c/login1.jpg' height='72' width='72'/><thr:total>46</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-6272142011254170521</id><published>2009-06-30T22:45:00.000-07:00</published><updated>2009-07-01T11:23:09.516-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><category scheme='http://www.blogger.com/atom/ns#' term='Dojo'/><title type='text'>Zend Framework and Dojo: configuration</title><content type='html'>Latest version of Zend framework- ZF 1.6.0 ship dojo toolkit. You can find it in ZendFramework-1.6.0/external/ directory when you download ZF.&lt;br /&gt;&lt;br /&gt;Recently I come across a problem using third party “calendar”- Java script Calendar, and as Zend has now done collaboration with Dojo, so people using zend will definitely start using Dojo for java scripts and all other functionality Dojo is providing. And that’s why I decided to study and use Dojo and implement it in my application instead of fixing the issue in the third party calendar.&lt;br /&gt;&lt;br /&gt;Although Zend has done excellent job and has made things quite easy for those who wish to use dojo in their applications, however novice and those with little experience may find it a bit difficult to configure Zend for Dojo.&lt;br /&gt;&lt;br /&gt;It this post I will tell you how to configure Zend for working with Dojo.&lt;br /&gt;&lt;br /&gt;The first and most important thing is to copy “external/dojo” into your js directory under www/public folder.&lt;br /&gt;&lt;br /&gt;After you copy the dojo folder add the following code in your bootstrap.&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;    $view = new Zend_View();&lt;br /&gt;&lt;br /&gt;    $view-&amp;gt;addHelperPath(&amp;#8217;Zend/Dojo/View/Helper/&amp;#8217;, &amp;#8216;Zend_Dojo_View_Helper&amp;#8217;);&lt;br /&gt;&lt;br /&gt;    $viewRenderer = new Zend_Controller_Action_Helper_ViewRenderer();&lt;br /&gt;&lt;br /&gt;    $viewRenderer-&amp;gt;setView($view);&lt;br /&gt;&lt;br /&gt;    Zend_Controller_Action_HelperBroker::addHelper($viewRenderer);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;Ignore the first line $view= new Zend_View() if you have already instantiated view object in your bootstrap file.&lt;br /&gt;&lt;br /&gt;That’s it. You have now added path to Dojo view helpers. You can now access dojo view helpers in your template-phtml file as you access other helper files and their functionality.&lt;br /&gt;&lt;br /&gt;You job has not done yet.&lt;br /&gt;&lt;br /&gt;Next you would need to add path to dojo.js file and other module of the dojo toolkit.&lt;br /&gt;&lt;br /&gt;So open your layout file and put following code.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;    if($this-&amp;gt;dojo()-&amp;gt;isEnabled()) {&lt;br /&gt;&lt;br /&gt;        $this-&amp;gt;dojo()-&amp;gt;setDjConfigOption(&amp;#8217;usePlainJson&amp;#8217;,true)&lt;br /&gt;&lt;br /&gt;                  -&amp;gt;addStylesheetModule(&amp;#8217;dijit.themes.tundra&amp;#8217;)&lt;br /&gt;&lt;br /&gt;                  -&amp;gt;setLocalPath(&amp;#8221;http://localhost/z/js/dojo/dojo/dojo.js&amp;#8221;);&lt;br /&gt;&lt;br /&gt;        echo $this-&amp;gt;dojo();&lt;br /&gt;&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;As you can see we are adding path to js and stylesheet files so put the above code in &amp;lt;head&amp;gt; tag of your layout file.&lt;br /&gt;&lt;br /&gt;The only thing you need to do is to enable dojo in your template file.&lt;br /&gt;&lt;br /&gt;Let suppose you have controller “IndexController”. So in the views/scripts/index/index.phtml file put the following code.&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;    $this-&amp;gt;dojo()-&amp;gt;enable()&lt;br /&gt;&lt;br /&gt;               -&amp;gt;requireModule(&amp;#8221;dijit.form.DateTextBox&amp;#8221;);&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;I would like to explain the last line -&amp;gt;requireModule(’dijit.form.DateTextBox’). This line tells php to load DateTextBox. DateTextBox render textbox that display calendar when someone click on the field.&lt;br /&gt;&lt;br /&gt;Your configuration is now completed. Now create your form as follows.&lt;br /&gt;&lt;pre style="font-family: Andale Mono, Lucida Console, Monaco, fixed, monospace; color: #000000; background-color: #eee;font-size: 12px;border: 1px dashed #999999;line-height: 14px;padding: 5px; overflow: auto; width: 100%"&gt;&lt;code&gt;class MyForm extends Zend_Dojo_Form&lt;br /&gt;&lt;br /&gt;{&lt;br /&gt;&lt;br /&gt;    public function init()&lt;br /&gt;    &lt;br /&gt;    {&lt;br /&gt;        $this-&amp;gt;setMethod('post');&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;setName('myform');&lt;br /&gt;        &lt;br /&gt;        $this-&amp;gt;addElement(&lt;br /&gt;            'DateTextBox',&lt;br /&gt;            'foo',&lt;br /&gt;             array(&lt;br /&gt;                &lt;br /&gt;                    'label'          =&amp;gt; 'Date:',&lt;br /&gt;                    'required'       =&amp;gt; true,&lt;br /&gt;                    'invalidMessage' =&amp;gt; 'Invalid date specified.',&lt;br /&gt;                    'formatLength'   =&amp;gt; 'long',&lt;br /&gt;                )&lt;br /&gt;        &lt;br /&gt;            );&lt;br /&gt;    &lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In your controller, write&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;    $form= new MyForm();&lt;br /&gt;&lt;br /&gt;    $this-&amp;gt;view-&amp;gt;form=$form;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;In your view template&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt; echo $this-&amp;gt;form;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;br /&gt;The last thing I’d mention is, In your layout file replace “body” tag with&lt;br /&gt;&lt;pre class="source-code"&gt;&lt;code&gt;body class=&amp;#8221;tundra&amp;#8221;&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-6272142011254170521?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/6272142011254170521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/06/zend-framework-and-dojo-configuration.html#comment-form' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6272142011254170521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/6272142011254170521'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/06/zend-framework-and-dojo-configuration.html' title='Zend Framework and Dojo: configuration'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-143279413877561994</id><published>2009-06-30T04:26:00.000-07:00</published><updated>2009-07-01T11:23:31.924-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Zend Framewrork'/><title type='text'>Zend Framework: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader</title><content type='html'>&lt;p&gt;While upgrading your version may cause the above warning.&lt;/p&gt; &lt;p&gt;To get rid of it replace the following code&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;require_once “Zend/Loader.php”;&lt;/p&gt; &lt;p&gt;Zend_Loader::registerAutoload();&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;With the following one.&lt;/p&gt; &lt;blockquote&gt;&lt;p&gt;require_once “Zend/Loader/Autoloader.php”;&lt;/p&gt; &lt;p&gt;$autoloader = Zend_Loader_Autoloader::getInstance();&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;Cheers&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-143279413877561994?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/143279413877561994/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/06/zend-framework-zendloaderzendloaderregi.html#comment-form' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/143279413877561994'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/143279413877561994'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/06/zend-framework-zendloaderzendloaderregi.html' title='Zend Framework: Zend_Loader::Zend_Loader::registerAutoload is deprecated as of 1.8.0 and will be removed with 2.0.0; use Zend_Loader_Autoloader'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-6572638285277330666.post-8453901019264366182</id><published>2009-06-30T04:02:00.000-07:00</published><updated>2009-07-01T11:23:50.045-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Php'/><title type='text'>PHP: Taking care of security</title><content type='html'>Today highly confidential data such as credit card number, social security number etc are stored and handle through web. So it must be your primary goal to make your web application secure enough, so that users/visitor feels confident enough while using your application.&lt;br /&gt;&lt;br /&gt;Here in this article I am going to give you some tips that are worthy to be remembered and taken care of in application development process.&lt;br /&gt;&lt;br /&gt;   1. You may have heard about register_globals. They make PHP variables usage easy. However they have certain disadvantages such as users can easily sneak into your application by easily passing data through $_POST, $_GET or $_COOKIE etc. So you shouldn’t rely on register_global. Disable them would be nice decision.&lt;br /&gt;   2. Most of the time we use variable directly, without first initializing them. For example&lt;br /&gt;&lt;br /&gt;if (condition) {&lt;br /&gt;&lt;br /&gt;$flag = TRUE;&lt;br /&gt;&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;If you don’t initialize $flag to false, user can easily set it to true using, $_POST, $_GET or $_COOKIE.&lt;br /&gt;&lt;br /&gt;   1. Verify all incoming data before processing. Verification highly depends on the type of data. If you need to insert integer data in the database, make sure that proper data is submitted through form.&lt;br /&gt;   2. Be very much careful when using function that run commands on the server. These function include exec(), passthru() and backticks (“) etc.&lt;br /&gt;   3. You must change the directory where session data is stored by default. Another good approach would be to use database to store session information.&lt;br /&gt;   4. When uploading file to the server, it would be good practice to rename the file(s) before storing them. Name must be safe and not guessable.&lt;br /&gt;   5. Don’t reveal error on live site. Errors reveal very important information, so they must be taken care of.&lt;br /&gt;   6. Take care of SQL injection. If user provides malicious information, your SQL query shouldn’t break.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/6572638285277330666-8453901019264366182?l=zendgeek.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://zendgeek.blogspot.com/feeds/8453901019264366182/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://zendgeek.blogspot.com/2009/06/php-taking-care-of-security.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8453901019264366182'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/6572638285277330666/posts/default/8453901019264366182'/><link rel='alternate' type='text/html' href='http://zendgeek.blogspot.com/2009/06/php-taking-care-of-security.html' title='PHP: Taking care of security'/><author><name>Faheem Abbas</name><uri>http://www.blogger.com/profile/00066665041342398401</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='29' height='32' src='http://4.bp.blogspot.com/_bn44g8iuZbQ/SLqIElM1IHI/AAAAAAAAABU/OPvCPOafEM8/S220/fahim.jpg'/></author><thr:total>0</thr:total></entry></feed>
