doudiyu1639 2010-10-05 11:11
浏览 14
已采纳

将变量传递给Zend Form

I have a zend form instantiated

$form = Form_Example();

Now I want to pass an ID from my controller to my form.

So I did this:

$form = Form_Example(array('id' => $id));

Inside the form I try to call it through:

$this->id

But it isn't there.

Anybody knows how to get that id into the form?

Thanks

  • 写回答

2条回答 默认 最新

  • duanemei2194 2010-10-05 12:35
    关注

    Make sure you have setter for the the element, in your case public function setId($id). Zend_Form constructor checks if setter method exists for the property, if it exists then it is called, otherwise it sets the attribute of the form, see setAttrib($key, $value).

    The end result will be something like this

    class Application_Form_YourForm extends Zend_Form {
    
        /**
         * Id
         * @var <type> 
         */
        protected $_id = null;
    
        /**
         * Setter for ID
         * @param <type> $id 
         */
        public function setId($id){
            $this->_id = $id;
        }
    
        // Rest of your code...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 C# TCP服务端,客户端退出后,不断有数据进来
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)
  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?