2012-04-20 99 views
0

您好我正在使用zend表单multicheckbox。Zend Form Multicheck dynamic

我有一个$数组,其中我有一个'id''name''姓氏''地址'和'城市'的用户列表。 我需要创建一个复选框中,我可以选择beetwen名+姓+加+城市和返回CONTROLER名字和姓氏选择的ID ...

这里是我的形式:

class Application_Form_MultiplaSelezione extends Zend_Form 
{ 
public function init() 
{ 
    /* Form Elements & Other Definitions Here ... */ 
} 

public function selezione($array){ 
    $this->setMethod('post');  
    $count=count($array);  
    $multipla=new Zend_Form_Element_MultiCheckbox('scelta');   
    for($i=0;i<$count;$i++){    
     foreach ($array[$i] as $chiave=>$valore){ 
      if($chiave=='idnomeutente'){ 
       $nomeutente=$valore; 
      } 
      if($chiave=='nome'){ 
       $nome=$valore; 
      } 
      if($chiave=='cognome'){ 
       $cognome=$valore; 
      } 
      if($chiave=='indirizzo'){ 
       $indirizzo=$valore; 
      } 
      if($chiave=='residenza'){ 
       $residenza=$valore; 
      } 

     } 
     $val=$nome.' '.$cognome.' '.$indirizzo.' '.$residenza; 
     $multipla->addMultiOption($nomeutente, $val); 


     if($i==0){ 
      $iduser=$nomeutente; 
     } 
    } 

    $multipla->setValue($iduser); 

    $submit= new Zend_Form_Element_Submit('submit'); 
    $submit->setLabel('Seleziona'); 

    $this->addElements(array($multipla,$submit));   
} 
    } 

为什么不起作用?

+0

你的代码不清楚,你的期望输出到底是什么? '$ array'包含什么? “返回控制器所选名称和姓氏的ID”是什么意思? – Liyali 2012-04-20 15:04:21

+0

另外,“为什么它不起作用”是向占卜者提问的好问题,在这里,大多数人可以首先在阅读错误时回答问题。什么不行? – Liyali 2012-04-20 15:31:11

+0

我写在数组中有一个id姓名地址和城市的用户列表。我想拥有一个包含所有元素的多重元素,并且我想选择它的ID。我说这是行不通的,因为如果我试图看到这个页面没有任何东西出现,并且浏览器继续加载某些东西...... – Simone 2012-04-20 16:44:47

回答

0

尝试阅读和理解:

<?php 

class Application_Form_MultiplaSelezione extends Zend_Form 
{ 
public function init() 
{ 
    $this->setMethod('post'); 

    $multipla=new Zend_Form_Element_MultiCheckbox('scelta'); 
    $multipla->setMultiOptions($this->getOptionsToMultipla()); 

    /* some other fields */ 

    $this->addElements(array(
     $multipla, 
     /* others fields */ 
     )); 
} 

public function getOptionsToMultipla() 
{ 
    /* there you can use static or dinamic method which: 
     1. select data from table 
     2. in foreach remake rows to your form, and add it to array ($array[] = "your string";) 
     3. return $array; 
     TIP: you should make other array where you have id of the rows, with it you can decode the request (compare index given from form) 
     (if you have problem with it I can help you in other thread :)*/ 

    /* for example of static method */ 
    return Your_Model::getOptionsToMultipla(); 
} 

要将此代码,您必须在您的模型和控制器添加一些变化。祝你好运:)

+0

我弄清楚什么是浏览器无法正常工作的问题。但是现在我有一个奇怪的问题。达到数组中信息的代码(用我的代码表示)不起作用。这很奇怪,因为我在控制器的操作之前使用了与相同数组相同的代码。我现在使用它的形式,我认为是相同的,但在代码不工作的形式....浏览器日志是:警告:无效的参数为foreach()提供...如果你认为这是更好,我会打开另一个帖子.. – Simone 2012-04-21 17:27:49

+0

尝试改变它http://pastebin.com/YTNXQgJb为它:http://pastebin.com/3wfa7BdR如果$ valore.cognom给出一个错误尝试改变它在$ valore ['cognom'] – 2012-04-21 17:47:15

+0

我发现问题是另一个...我通过行动之间的数组$ this - > _ helper-> redirector('action','controller',NULL,array('array'=> $阵列));重定向似乎不太好... – Simone 2012-04-21 17:57:32