Foros del Web » Programando para Internet » PHP » Zend »

Error de String en Aplicacion

Estas en el tema de Error de String en Aplicacion en el foro de Zend en Foros del Web. Saludos a Todos. Sucede que tengo una aplicacion en zend framework en la cual implemento un loguin y por medio de este que me muestre ...
  #1 (permalink)  
Antiguo 14/10/2011, 20:22
Avatar de danj  
Fecha de Ingreso: octubre-2011
Ubicación: Calarcho
Mensajes: 53
Antigüedad: 12 años, 5 meses
Puntos: 1
Información Error de String en Aplicacion

Saludos a Todos.

Sucede que tengo una aplicacion en zend framework en la cual implemento un loguin y por medio de este que me muestre que registros tiene un usuario en particular, es decir el que esta logueado en la aplicacion, pero me sucede el siguiente error y no se de donde proviene ni porque se produce.

Gracias por su colaboracion.

An error occurred

Application error

Exception information:

Message: Elements specified by string must have an accompanying name

Stack trace:

#0 C:\zendServer\ZendServer\share\ZendFramework\libra ry\Zend\Form.php(1132): Zend_Form->addElement('admin', NULL)
#1 C:\zendServer\www\sagas\application\forms\Principa lForm.php(37): Zend_Form->addElements(Array)
#2 C:\zendServer\www\sagas\application\controllers\Pr incipalController.php(22): Form_PrincipalForm->__construct()
#3 C:\zendServer\ZendServer\share\ZendFramework\libra ry\Zend\Controller\Action.php(516): PrincipalController->principalAction()
#4 C:\zendServer\ZendServer\share\ZendFramework\libra ry\Zend\Controller\Dispatcher\Standard.php(295): Zend_Controller_Action->dispatch('principalAction')
#5 C:\zendServer\ZendServer\share\ZendFramework\libra ry\Zend\Controller\Front.php(954): Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#6 C:\zendServer\ZendServer\share\ZendFramework\libra ry\Zend\Application\Bootstrap\Bootstrap.php(97): Zend_Controller_Front->dispatch()
#7 C:\zendServer\ZendServer\share\ZendFramework\libra ry\Zend\Application.php(366): Zend_Application_Bootstrap_Bootstrap->run()
#8 C:\zendServer\www\sagas\public\index.php(37): Zend_Application->run()
#9 {main}
Request Parameters:

array (
'controller' => 'principal',
'action' => 'principal',
'module' => 'default',
)
  #2 (permalink)  
Antiguo 14/10/2011, 21:52
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Error de String en Aplicacion

Podrías mostrar el código de tu formulario (PrincipalForm) porque de ahí viene el error.

Saludos.
  #3 (permalink)  
Antiguo 14/10/2011, 22:54
Avatar de danj  
Fecha de Ingreso: octubre-2011
Ubicación: Calarcho
Mensajes: 53
Antigüedad: 12 años, 5 meses
Puntos: 1
Respuesta: Error de String en Aplicacion

Sii claro espero me puedan ayudar!

PrincipalForm.php

Código PHP:
Ver original
  1. <?php
  2. class Form_PrincipalForm extends Zend_Form
  3. {
  4.     public function __construct($option = null){
  5.         parent::__construct($option);
  6.        
  7.         $this->setName('opciones');
  8.        
  9.         $usuario = new Zend_Form_Element_Hidden('idusuarios');
  10.    
  11.        $nombre = new Zend_Form_Element_Text('usuarios');  
  12.          $nombre->setLabel('USUARIOS')  
  13.          ->setRequired(true)  
  14.          ->addFilter('StripTags')  
  15.          ->addFilter('StringTrim')  
  16.          ->addValidator('NotEmpty');
  17.            
  18.          $submit = new Zend_Form_Element_Submit('submit');  
  19.          $submit->setAttrib('idusuarios','submitbutton');  
  20.         // $this->addElements(array($usuario,$nombre,$submit));
  21.          
  22.        
  23.         $opciones = new Zend_Form_Element_Select('opcion');
  24.         $opciones->setLabel('Roles')
  25.                  ->setAttrib('onchange','prueba()');
  26.                
  27.         $opciones->addMultiOption('','SELECIONE UN ROL');        
  28.         $tabla = new CuentasUsuariosModel();       
  29.         $mysesion = new Zend_Session_Namespace('mysesion');
  30.         $usuario=$mysesion->usuario;
  31.         $password=$mysesion->password;
  32.        
  33.         foreach ($tabla->consultarCuentas($usuario, $password)as $rows){
  34.             $opciones->addMultiOption($rows->idroles, $rows->nombre);
  35.         }
  36.                
  37.         $this->addElements(array($opciones,$usuario,$nombre,$submit));
  38.  
  39.     ?>
  40.    
  41. <table>
  42. <tr>
  43.         <th>Estado</th>
  44.         <th>Solicitud Herramientas</th>
  45.         <th>Nombres</th>
  46.         <th>Fecha</th>
  47.         <th>Fecha Estimada Devolucion</th>
  48.         <th>&nbsp;</th>
  49. </tr>
  50. <?php
  51.         $tabla2 = new CuentasUsuariosModel();      
  52.         foreach ($tabla2->consultarFechas($usuario)as $rows1){ 
  53.    
  54.         /*$fechaUno = new Zend_Date();
  55.         Zend_Date::setOptions(array('format_type' => 'php'));
  56.         $date=new Zend_Date($fechaUno);
  57.         print $date->toString('Y-m-d');*/
  58.            
  59.             ?>
  60. <tr>
  61. <td><?php      
  62.                
  63.         /*$fechaUno = new Zend_Date(strtotime('11/10/2011 00:00:00'));         
  64.         $fechaUno->toString("YYYY.MM.dd HH:mm:ss");
  65.         echo $fechaUno;*/
  66.        
  67.        
  68.         $fechaDevolucion = $rows1->fechaEstimadaDevolucion;
  69.            
  70.         //echo $fechaDos->get('yyyy-mm-dd');
  71.         if(date("Y-m-d") > $fechaDevolucion) {
  72.          echo '<img src="/img/rojo.png">';
  73.         }
  74.         if(date("Y-m-d") <= $fechaDevolucion) {
  75.          echo '<img src="/img/verde.png">';
  76.         } else {
  77.          echo '<!--<img src="/img/gris.png">-->';
  78.         }   ?></td>
  79. <td><?php echo $rows1->idsolicitudHerramientas; ?></td>
  80. <td><?php echo $rows1->nombres; ?></td>
  81. <td><?php echo $rows1->fecha; ?></td>
  82. <td><?php echo $rows1->fechaEstimadaDevolucion; }?></td>
  83. </tr>  
  84.    
  85. </table>
  86.  
  87. <div id="div_3" class="contenido" style="display: none;">
  88. <p align="center"><h2>Prestamos De Todos Los Usuarios</h2></p>
  89. <br>
  90.             <table>
  91. <tr>       
  92.         <th>Estado</th>
  93.         <th>Solicitud Herramientas</th>
  94.         <th>Nombres</th>
  95.         <th>Fecha</th>
  96.         <th>Fecha Estimada Devolucion</th>
  97.         <th>&nbsp;</th>
  98. </tr>
  99. <?php
  100.         $tabla3 = new CuentasUsuariosModel();      
  101.         foreach ($tabla3->consultarFechasTotal()as $rows2){
  102.    
  103.         /*$fechaUno = new Zend_Date();
  104.         Zend_Date::setOptions(array('format_type' => 'php'));
  105.         $date=new Zend_Date($fechaUno);
  106.         print $date->toString('Y-m-d');*/
  107.            
  108.             ?>
  109. <tr>
  110. <td><?php      
  111.                
  112.         /*$fechaUno = new Zend_Date(strtotime('11/10/2011 00:00:00'));         
  113.         $fechaUno->toString("YYYY.MM.dd HH:mm:ss");
  114.         echo $fechaUno;*/
  115.        
  116.        
  117.         $fechaDevolucion = $rows2->fechaEstimadaDevolucion;
  118.            
  119.         //echo $fechaDos->get('yyyy-mm-dd');
  120.         if(date("Y-m-d") > $fechaDevolucion) {
  121.          echo '<img src="/img/rojo.png">';
  122.         }
  123.         if(date("Y-m-d") <= $fechaDevolucion) {
  124.          echo '<img src="/img/verde.png">';
  125.         } else {
  126.          echo '<!--<img src="/img/gris.png">-->';
  127.         }   ?></td>
  128. <td><?php echo $rows2->idsolicitudHerramientas; ?></td>
  129. <td><?php echo $rows2->nombres; ?></td>
  130. <td><?php echo $rows2->fecha; ?></td>
  131. <td><?php echo $rows2->fechaEstimadaDevolucion; }?></td>
  132. </tr>  
  133.    
  134. </table>
  135.         </div>
  136.        
  137.         <?php
  138. $tabla = new solcitudesmaterialModel();
  139.                                
  140.                                
  141.                                
  142.                                foreach ( $tabla->actualizar()as $c)
  143.                                {
  144.                                 echo "<table border=\"1\" align=\"center\">";
  145.                                 echo "<tr><th>fecha</th>";
  146.                                                echo "<th>estado solicitud</th>";
  147.                                                 echo "<tr><td>";
  148.                                     echo $c -> fecha;
  149.                                     echo "</td><td>";
  150.                                     echo $c -> estado;
  151.                                     echo "</td></tr>";
  152.                                     echo "</table>";
  153.                                }
  154.     }}                                 
  155. ?>

Saludos.
  #4 (permalink)  
Antiguo 14/10/2011, 22:57
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 17 años, 10 meses
Puntos: 2135
Respuesta: Error de String en Aplicacion

Ese codigo esta muy mal hecho, ¿porque inyectas todo ese código que debe de ir en un template en la forma?

$this->addElements() soporta solamente un array de controles, y te lo indica la excepción, tu le estas pasando una variable que es un string ($usuario) y aunque más arriba creas el elemento luego te "pisas" esa variable usando $usuario=$mysesion->usuario; por eso te marca la excepción.
  #5 (permalink)  
Antiguo 15/10/2011, 18:55
Avatar de danj  
Fecha de Ingreso: octubre-2011
Ubicación: Calarcho
Mensajes: 53
Antigüedad: 12 años, 5 meses
Puntos: 1
Respuesta: Error de String en Aplicacion

Siii gracias.
ya pude corregir el error, y era por el elemento hidden.

Saludos.
  #6 (permalink)  
Antiguo 19/10/2011, 06:43
 
Fecha de Ingreso: junio-2011
Mensajes: 51
Antigüedad: 12 años, 9 meses
Puntos: 3
Respuesta: Error de String en Aplicacion

Cita:
Iniciado por danj Ver Mensaje
Sii claro espero me puedan ayudar!

PrincipalForm.php

Código PHP:
Ver original
  1. <?php
  2. class Form_PrincipalForm extends Zend_Form
  3. {
  4.     public function __construct($option = null){
  5.         parent::__construct($option);
  6.        
  7.         $this->setName('opciones');
  8.        
  9.         $usuario = new Zend_Form_Element_Hidden('idusuarios');
  10.    
  11.        $nombre = new Zend_Form_Element_Text('usuarios');  
  12.          $nombre->setLabel('USUARIOS')  
  13.          ->setRequired(true)  
  14.          ->addFilter('StripTags')  
  15.          ->addFilter('StringTrim')  
  16.          ->addValidator('NotEmpty');
  17.            
  18.          $submit = new Zend_Form_Element_Submit('submit');  
  19.          $submit->setAttrib('idusuarios','submitbutton');  
  20.         // $this->addElements(array($usuario,$nombre,$submit));
  21.          
  22.        
  23.         $opciones = new Zend_Form_Element_Select('opcion');
  24.         $opciones->setLabel('Roles')
  25.                  ->setAttrib('onchange','prueba()');
  26.                
  27.         $opciones->addMultiOption('','SELECIONE UN ROL');        
  28.         $tabla = new CuentasUsuariosModel();       
  29.         $mysesion = new Zend_Session_Namespace('mysesion');
  30.         $usuario=$mysesion->usuario;
  31.         $password=$mysesion->password;
  32.        
  33.         foreach ($tabla->consultarCuentas($usuario, $password)as $rows){
  34.             $opciones->addMultiOption($rows->idroles, $rows->nombre);
  35.         }
  36.                
  37.         $this->addElements(array($opciones,$usuario,$nombre,$submit));
  38.  
  39.     ?>
  40.    
  41. <table>
  42. <tr>
  43.         <th>Estado</th>
  44.         <th>Solicitud Herramientas</th>
  45.         <th>Nombres</th>
  46.         <th>Fecha</th>
  47.         <th>Fecha Estimada Devolucion</th>
  48.         <th>&nbsp;</th>
  49. </tr>
  50. <?php
  51.         $tabla2 = new CuentasUsuariosModel();      
  52.         foreach ($tabla2->consultarFechas($usuario)as $rows1){ 
  53.    
  54.         /*$fechaUno = new Zend_Date();
  55.         Zend_Date::setOptions(array('format_type' => 'php'));
  56.         $date=new Zend_Date($fechaUno);
  57.         print $date->toString('Y-m-d');*/
  58.            
  59.             ?>
  60. <tr>
  61. <td><?php      
  62.                
  63.         /*$fechaUno = new Zend_Date(strtotime('11/10/2011 00:00:00'));         
  64.         $fechaUno->toString("YYYY.MM.dd HH:mm:ss");
  65.         echo $fechaUno;*/
  66.        
  67.        
  68.         $fechaDevolucion = $rows1->fechaEstimadaDevolucion;
  69.            
  70.         //echo $fechaDos->get('yyyy-mm-dd');
  71.         if(date("Y-m-d") > $fechaDevolucion) {
  72.          echo '<img src="/img/rojo.png">';
  73.         }
  74.         if(date("Y-m-d") <= $fechaDevolucion) {
  75.          echo '<img src="/img/verde.png">';
  76.         } else {
  77.          echo '<!--<img src="/img/gris.png">-->';
  78.         }   ?></td>
  79. <td><?php echo $rows1->idsolicitudHerramientas; ?></td>
  80. <td><?php echo $rows1->nombres; ?></td>
  81. <td><?php echo $rows1->fecha; ?></td>
  82. <td><?php echo $rows1->fechaEstimadaDevolucion; }?></td>
  83. </tr>  
  84.    
  85. </table>
  86.  
  87. <div id="div_3" class="contenido" style="display: none;">
  88. <p align="center"><h2>Prestamos De Todos Los Usuarios</h2></p>
  89. <br>
  90.             <table>
  91. <tr>       
  92.         <th>Estado</th>
  93.         <th>Solicitud Herramientas</th>
  94.         <th>Nombres</th>
  95.         <th>Fecha</th>
  96.         <th>Fecha Estimada Devolucion</th>
  97.         <th>&nbsp;</th>
  98. </tr>
  99. <?php
  100.         $tabla3 = new CuentasUsuariosModel();      
  101.         foreach ($tabla3->consultarFechasTotal()as $rows2){
  102.    
  103.         /*$fechaUno = new Zend_Date();
  104.         Zend_Date::setOptions(array('format_type' => 'php'));
  105.         $date=new Zend_Date($fechaUno);
  106.         print $date->toString('Y-m-d');*/
  107.            
  108.             ?>
  109. <tr>
  110. <td><?php      
  111.                
  112.         /*$fechaUno = new Zend_Date(strtotime('11/10/2011 00:00:00'));         
  113.         $fechaUno->toString("YYYY.MM.dd HH:mm:ss");
  114.         echo $fechaUno;*/
  115.        
  116.        
  117.         $fechaDevolucion = $rows2->fechaEstimadaDevolucion;
  118.            
  119.         //echo $fechaDos->get('yyyy-mm-dd');
  120.         if(date("Y-m-d") > $fechaDevolucion) {
  121.          echo '<img src="/img/rojo.png">';
  122.         }
  123.         if(date("Y-m-d") <= $fechaDevolucion) {
  124.          echo '<img src="/img/verde.png">';
  125.         } else {
  126.          echo '<!--<img src="/img/gris.png">-->';
  127.         }   ?></td>
  128. <td><?php echo $rows2->idsolicitudHerramientas; ?></td>
  129. <td><?php echo $rows2->nombres; ?></td>
  130. <td><?php echo $rows2->fecha; ?></td>
  131. <td><?php echo $rows2->fechaEstimadaDevolucion; }?></td>
  132. </tr>  
  133.    
  134. </table>
  135.         </div>
  136.        
  137.         <?php
  138. $tabla = new solcitudesmaterialModel();
  139.                                
  140.                                
  141.                                
  142.                                foreach ( $tabla->actualizar()as $c)
  143.                                {
  144.                                 echo "<table border=\"1\" align=\"center\">";
  145.                                 echo "<tr><th>fecha</th>";
  146.                                                echo "<th>estado solicitud</th>";
  147.                                                 echo "<tr><td>";
  148.                                     echo $c -> fecha;
  149.                                     echo "</td><td>";
  150.                                     echo $c -> estado;
  151.                                     echo "</td></tr>";
  152.                                     echo "</table>";
  153.                                }
  154.     }}                                 
  155. ?>

Saludos.
Este es, como bien dice GatorV, un claro ejemplo de como NO se debe hacer un form en Zend.

Etiquetas: framework
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 03:30.