dongzhiyong8577 2010-09-15 19:19
浏览 30
已采纳

Zend表单元素的自动完成

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 = $this->createElement('DateTextBox', 'date',

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

    );

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

  • 写回答

2条回答 默认 最新

  • dongqie5529 2010-09-15 20:54
    关注

    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();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比