开发者

Auto-completion for Zend Form Elements

开发者 https://www.devze.com 2023-01-16 03:02 出处:网络
When creating form elements with Zend (using Zend Studio for Eclipse), I\'d like some auto completion or hints. Here\'s what I\'m thinking. I\'m sure these exist, but I don\'t know how to get them.

When creating form elements with Zend (using Zend Studio for Eclipse), I'd like some auto completion or hints. Here's what I'm thinking. I'm sure these exist, but I don't know how to get them.

  • I type createElement and auto-completes gives me the signature createElement($type, $name). Great, I select it.

  • but when I try to set the $type I don't get any hints like DateTextBox or ValidationTextBox. Being new, I see how this can be useful. What do you do to remember all the options?

  • for the array of attributes like require, invalidMessage, I'd like to get a list of those to choose from, and/or auto-complete when I start typing one.

    // Date field

    $date = $thi开发者_Python百科s->createElement('DateTextBox', 'date',

    array('require' => 'true', 'invalidMessage' => 'Invalid date format')

    );

    $date->setLabel('date')->setRequired(true);


You have few options to help yourself, without waiting for any plugin:

  • learn it and remember ;)
  • extend your phpDoc blocks with all available options:

Example (to be honest I don't know if Eclipse supports html in phpDoc or even any text after variable name in @param, but it works fine in Netbeans):

/**
 * [...]
 * @param  string $type Can be: <ul><li>DateTextBox</li><li>ValidationTextBox</li></ul>
 * @param  string $name Whatever
 * @param  array|Zend_Config $options Array with following keys: <ul><li>require</li><li>invalidMessage</li></ul>
 * @return Zend_Form_Element
 */
public function createElement($type, $name, $options = null)
  • extend Zend class and create your own methods to simplify your work

Example:

class My_Zend_Form_Element extends Zend_Form_Element    
{   
    public function createDateTextBox($name, $options = null)
    {
        return $this->createElement('DateTextBox', $name, $options);
    }
}
  • declare some well named constants and provide some hint in phpDoc

Example: (type ZFE_OPTIONS and IDE should show hint with some constants to use as array keys)

/**
 * Can be true or false
 */
define('ZFE_OPTIONS_REQUIRE','require');
  • create your own helper classes with methods to produce valid options array

Example:

class ZFE_Options
{
    protected $opts = array();

    /**
     * @param bool $req
     * @return ZFE_Options 
     */
    public function setRequired($req){
        $this->opts['require'] = (bool)$req;
        return $this;
    }

    /**
     * @param string $txt
     * @return ZFE_Options 
     */
    public function setInvalidMessage($txt){
        $this->opts['invalidMessage'] = (string)$txt;
        return $this;
    }

    /**
     * @return array
     */
    public function toArray(){
        return $this->opts;
    }
}

$zfe_options = new ZFE_Options();
$opts = $zfe_options
            ->setRequired(true)
            ->setInvalidMessage('Please provide valid email address')
            ->toArray();


That's not possible. It's not how autocompletion works. The hints you get are taken directly from ZF's code documentation. Nothing more, nothing less. Everything you see as hints is taken directly from the DocBlock and method signature, e.g.

   /**
     * Create an element
     *
     * Acts as a factory for creating elements. Elements created with this
     * method will not be attached to the form, but will contain element
     * settings as specified in the form object (including plugin loader
     * prefix paths, default decorators, etc.).
     *
     * @param  string $type
     * @param  string $name
     * @param  array|Zend_Config $options
     * @return Zend_Form_Element
     */
    public function createElement($type, $name, $options = null)

Eclipse can tell you to insert a string or an array and it will know that the method returns a Zend_Form_Element, but it cannot tell you what these strings should be.

The only place where I know something like what you describe exists is for CSS files. For some reason, when I type in display: it will give me an autocomplete box with possible values for this declaration. If you want more sophisticated autocomplete like this, consider filing this as a feature request to Zend.

0

精彩评论

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