Get Boot­strap Resource every­where across your Zend_Application

March 2nd, 2010

Some­times you need to access some resources cre­ated inside your boot­strap some­where deep inside your applic­a­tion. There are two ways to achieve this. First is to use Zend_Registry, and second is to use resources of your boot­strap dir­ectly. Before we’ll fol­low, please ask your self: “Am I really need this?”, because in most cases you don’t need it, so this is a use­less post.
Read the rest of this entry »

Bind model to the Zend_Form…

February 3rd, 2010

In my pre­vi­ous post I have described how to fill model with val­ues from the Zend_Form. But reverse pro­cess is also very import­ant. If you are using Zend_Db_Table you prob­ably will not need any spe­cial meth­ods as you can use Zend_Form::setDefault($array) built-in method. But if you are work­ing with Doc­trine ORM or some­thing sim­ilar you’ll need to use your own method to read model’s data and put it into the form. So today I’m going to show how to pop­u­late field val­ues of Zend_Form from model. With tra­di­tional example applic­a­tion :))
Read the rest of this entry »

Test if request is really dis­patch­able in Zend Framework

February 2nd, 2010

Some­times you need to check if request is dis­patch­able. The most com­mon place where you can meet this need is in con­trol­ler plug-in. I have met that I need to test if request is dis­patch­able when I have imple­men­ted my App_Controller_Plugin_Acl for ACL check­ing based on ZF pro­posal. So ACL test is run before request will be dis­patched. Of course I don’t want to run ACL checks for requests that are not dis­patch­able. I relay on stand­ard dispatcher’s Zend_Controller_Disptcher_Interface::isDispatchable() and that was my mis­take — as I spent hours try­ing to under­stand what I’m doing wrong. Yes! The prob­lem was that isDispatchable() doesn’t care about actions — it tests con­trol­ler exist­ence only. But for­tu­nately it still can be eas­ily tested…
Read the rest of this entry »

Bind Zend_Form val­ues to the model. Part 2 (Array-type properties)

January 7th, 2010

In my pre­vi­ous post I’ve added a simple bind­ing func­tion­al­ity to Zend_Form. But once I’ve imple­men­ted it in real world with Doc­trine PHP ORM as my BLL, I found that it can’t work seam­lessly with my model’s prop­er­ties of array type. In fact you’ll feel the same prob­lem with Zend_Db_Table based mod­els if you have fields rep­res­ent­ing arrays. The simplest solu­tion, as I had only one such-typed prop­erty in my model, was to over­ride My_Form::fill() method in con­crete form. But as we speak about reusable code I imple­men­ted it in My_Form dir­ectly…
Read the rest of this entry »

Bind Zend_Form to the model

January 1st, 2010

Zend Frame­work has great com­pon­ent — Zend_Form which can be used to cre­ate a reusable form. So you can cre­ate a com­mon form, for example, for both new user regis­tra­tion and user pro­file editor. In most cases such form will rep­res­ent your model. So you’ll cre­ate a lot of repet­it­ive code for filling model’s prop­er­ties with form val­ues. Instead of this you can write a bind­ing meth­ods so your form will know how to bind itself to your model…
Read the rest of this entry »