开发者

which is best way for making form in zend framework

开发者 https://www.devze.com 2023-01-23 06:09 出处:网络
It is possible to make form and table (View)by both using zend_form with decorators, validators , filters etc, and we can also do this directly in view phtml file writing html as usual. I want to know

It is possible to make form and table (View) by both using zend_form with decorators, validators , filters etc, and we can also do this directly in view phtml file writing html as usual. I want to know which one is the best way to do in terms开发者_StackOverflow of

  1. Performance
  2. Time
  3. Simplicity

I am new to zend framework.


Performance

Can always be increased by caching, better machine.

Time

Just learn your IDE, it will code the forms for you (macros, shortcuts, templates etc.)

Simplicity

Zend From usage couldn't be simpler. You may even just create the form by writing plain text (ini syntax).


So, newer create forms in the view.


The best way:

// application/modules/search/forms/Search.php

class Search_Form_Search extends Application_Form_Abstract
{
    public function init()
    {
      $this->addElements(array(
          // other elements here
          new Zend_Form_Element_Submit('search_submit'),
      ));
    }
}

In the model:

// application/modules/search/models/Search.php

...
public function getForm()
{
    return new Search_Form_Search();
}


I think that using forms in view script is the best way, because:

  1. It's more flexible way
  2. It's better for perfomance
  3. Other nonzend developer can understand your code

Excuse me for my English


The best way is described in the docs. Don't write it at hand. Even considering the eventual possibility of it being faster it's something you don't want to do at all: Hardware is cheap. Labor is not.

And now imagine you've to get from the floor A to B, C, D... If you use the elevator every time you're less prone to errors (giving that the elevator is a box you just come in, press a single button, travel during some time on it and then come out) than if you use the stairs (you've to lift your feet different ways to go up/down, have to check every single step you do as well as every single stair (maybe there's water leaking from the floor), etc).

  • doing exercise is not the point.

See Keep it simple, Stupid!

0

精彩评论

暂无评论...
验证码 换一张
取 消