Ver Mensaje Individual
  #1 (permalink)  
Antiguo 21/03/2013, 15:01
kaleltas
 
Fecha de Ingreso: abril-2008
Mensajes: 14
Antigüedad: 16 años
Puntos: 0
Como llenar un select desde la base de datos?

hola a todos, he realizo el getting started de la pagina de zf2 he avanzado un poco en mi propio proyecto segun la guia de zend. pero ahora llegue a un inconveniente que describo asi:


tengo 2 tablas User y Portal con estructura:

User Portal
id id
name name
........ url
portal_id


para la creacion de User necesito llenar un combo con los datos almancenados en portal, por lo cual en mi UserForm la tengo definida asi:


Código PHP:
<?php
namespace RegisterForm
;

use 
ZendDiServiceLocator;

use 
ZendCaptchaAdapterInterface as CaptchaAdapter;
use 
ZendFormForm;
use 
ZendFormElement;

class 
UserForm extends Form
{
    
//     protected $captcha;

    
public function __construct($name null)
    {
        
parent::__construct('user');
        
$this->setAttribute('method''post');
        
$this->setAttribute('class''form-horizontal');

        
$this->add(array(
                
'name' => 'id',
                
'attributes' => array(
                        
'type'  => 'hidden',
                ),
        ));

        
$this->add(array(
                
'type' => 'Select',
                
'name' => 'portal_id',
                
'options' => array(
                        
'label' => 'Portal',
                        
'empty_option' => 'Seleccione un portal',
                        
'value_options' => array(
                                
'1' => 'Portal 1',
                                
'2' => 'Portal 2',
                                
'3' => 'Portal 3',
                        ),
                        
                )
        ));

        
$this->add(array(
                
'name' => 'firstName',
                
'attributes' => array(
                        
'type'  => 'text',
                ),
                
'options' => array(
                        
'label' => 'First Name',
                ),
        ));

        
$this->add(array(
                
'name' => 'lastName',
                
'attributes' => array(
                        
'type'  => 'text',
                ),
                
'options' => array(
                        
'label' => 'Last Name',
                ),
        ));
        
$this->add(array(
                
'name' => 'login',
                
'attributes' => array(
                        
'type'  => 'text',
                ),
                
'options' => array(
                        
'label' => 'Login',
                ),
        ));

        
$this->add(array(
                
'name' => 'password',
                
'attributes' => array(
                        
'type'  => 'password',
                ),
                
'options' => array(
                        
'label' => 'Password',
                ),
        ));

        
$this->add(array(
                
'name' => 'password_repeat',
                
'attributes' => array(
                        
'type'  => 'password',
                ),
                
'options' => array(
                        
'label' => 'password (repeat)',
                ),
        ));

        
$this->add(array(
                
'name' => 'email',
                
'attributes' => array(
                        
'type'  => 'text',
                ),
                
'options' => array(
                        
'label' => 'Email',
                ),
        ));


            
$this->add(array(
                
'name' => 'submit',
                
'attributes' => array(
                        
'type'  => 'submit',
                        
'value' => 'Go',
                        
'id' => 'submitbutton',
                ),
        ));
    }
}
de la clase anterior lo único necesario del problema es ver el elemento Select, actualmente esta llenado de forma estático con 3 valores: portal 1, portal 2 y portal 3.


Código PHP:
$this->add(array(
                
'type' => 'Select',
                
'name' => 'portal_id',
                
'options' => array(
                        
'label' => 'Portal',
                        
'empty_option' => 'Seleccione un portal',
                                                
// agregar arreglo con opciones de la base de datos
                        
'value_options' => array(
                                
'1' => 'Portal 1',
                                
'2' => 'Portal 2',
                                
'3' => 'Portal 3',

                        ),
                        
                )
        )); 
Espero explicarlo de manera adecuada, gracias por su ayuda.