Ver Mensaje Individual
  #9 (permalink)  
Antiguo 29/12/2010, 07:00
Avatar de alfcm
alfcm
 
Fecha de Ingreso: mayo-2009
Mensajes: 291
Antigüedad: 15 años
Puntos: 7
Respuesta: unset en Zend

Hola masterpuppet, bueno aqui posteo todo mi controller y no uso ningun stop,writable, solo use una vez el destroy para hacer nuevas pruebas luego lo comente

Este controller es de un carrito de compras, y el metodo quitarAction es donde quiero hacer un unset ,y bueno lo encerre en un try catch porque uso ajax y me lo muestra en el firebug

Te comento que los demas metodos me funcionan de agregarAction, el cual me setea valores, pero el quitarAction me manda el error que de comente

Código PHP:
Ver original
  1. <?php
  2.  
  3. class OrdenController extends Zend_Controller_Action{
  4.    
  5.     protected $logger;
  6.     private $orden;
  7.     private $orden_n; //orden nueva
  8.    
  9.     public function init(){
  10.         $this->logger = Zend_Registry::get('logger');
  11.     }
  12.    
  13.     public function preDispatch(){ 
  14.         //Zend_Session::destroy();
  15.     }
  16.    
  17.     public function indexAction(){
  18.         $this->view->titulo = 'Orden de Compras';  
  19.     }
  20.    
  21.     public function agregarAction(){
  22.         $this->orden = new Zend_Session_Namespace('orden');
  23.        
  24.         ($this->orden->cont == null)?$this->orden->cont=0:$this->orden->cont=$this->orden->cont;
  25.        
  26.         $this->orden->cont = $this->orden->cont + 1;
  27.        
  28.         $this->orden->id[$i] = $this->_getParam('id');
  29.         $this->orden->nombre[$i] = $this->_getParam('nombre');
  30.         $this->orden->precio[$i] = $this->_getParam('precio');
  31.         $this->orden->cantidad[$i] = $this->_getParam('cantidad');
  32.  
  33.         $this->_helper->viewRenderer->setNoRender();
  34.         $this->_helper->layout->disableLayout();
  35.     }
  36.    
  37.     public function quitarAction(){
  38.         $x = 1;
  39.         $this->_helper->viewRenderer->setNoRender();
  40.         $this->_helper->layout->disableLayout();
  41.        
  42.         try{
  43.             unset($this->orden);
  44.             unset($this->orden_n);
  45.             Zend_Session::namespaceUnset('orden');
  46.             Zend_Session::namespaceUnset('orden_n');   
  47.         }catch(Exception $e){  
  48.             $this->logger->log("UNSET SESION ".$e->getMessage(),Zend_Log::ERR);
  49.         }
  50.  
  51.         $this->orden = new Zend_Session_Namespace('orden');
  52.         $this->orden_n = new Zend_Session_Namespace('orden_n');
  53.  
  54.         for($i=1; $i<= $this->orden->cont; $i++){
  55.             if($this->orden->id[$i] != $this->_getParam('id')){
  56.                 $this->orden_n->id[$x]= $this->orden->id[$i];
  57.                 $this->orden_n->nombre[$x]= $this->orden->nombre[$i];
  58.                 $this->orden_n->precio[$x]= $this->orden->precio[$i];
  59.                 $this->orden_n->cantidad[$x]= $this->orden->cantidad[$i];
  60.                 $this->orden_n->cont= $x;
  61.                 $x+=1; 
  62.             }
  63.         }
  64.  
  65.         $this->orden = new Zend_Session_Namespace('orden');
  66.  
  67.         for($i=1; $i<= $this->orden_n->cont; $i++){
  68.    
  69.             $this->orden->id[$i]= $this->orden_n->id[$i];
  70.             $this->orden->nombre[$i]= $this->orden_n->nombre[$i];
  71.             $this->orden->precio[$i]= $this->orden_n->precio[$i];
  72.             $this->orden->cantidad[$i]= $this->orden_n->cantidad[$i];
  73.             $this->orden->cont= $i;
  74.         }
  75.     }
  76.    
  77.     public function preventaAction(){
  78.  
  79.         $this->_helper->viewRenderer->setNoRender();
  80.         $this->_helper->layout->disableLayout();
  81.        
  82.         $this->orden = new Zend_Session_Namespace('orden');
  83.             $tabla="<div style='font-family:Verdana' align='right'><a href='http://192.168.40.100/pruebajax/public/orden/reset' id='nuevaorden'>Nueva Orden</a></div>";
  84.             $tabla.="<br/><div style='font-family:Verdana;font-size:11px;' align='center'>
  85.                 <table width='80%' border='1' style='border-collapse:collapse'>";
  86.             $tabla.="<thead style='background-color:#BBBBBB'><tr><th>ITEM</th><th>DESCRIPCION</th><th>CANTIDAD</th><th>PRECIO</th><th>MONTO</th><th>&nbsp;</th></tr></thead>";
  87.            
  88.             for($i=1; $i <= $this->orden->cont; $i++){
  89.                 $tabla.="<tr><td>".$i."</td>
  90.                              <td>".$this->orden->nombre[$i]."</td>
  91.                              <td align='center' width='8%'>
  92.                              <input type='text' name='cantidad[".$i."]'
  93.                              value='".$this->orden->cantidad[$i]."' size='8' style='text-align:right'/></td>
  94.                              <td align='right'>".number_format($this->orden->precio[$i],2,'.',',')."</td>
  95.                              <td align='right'>S/. ".number_format($this->orden->precio[$i]*$this->orden->cantidad[$i],2,'.',',')."</td>
  96.                              <td align='center'><a href='' title='Quitar del Pedido' onclick='quitar(".$this->orden->id[$i].",event)'>
  97.                              <img src='http://192.168.40.100/pruebajax/public/img/drop.gif' style='border:0px'
  98.                              /></a></td>
  99.                              </tr>";
  100.                 $total += $this->orden->precio[$i]*$this->orden->cantidad[$i];  
  101.             }
  102.             $this->orden->monto = $total;
  103.  
  104.             $tabla.="<tr><td colspan='4' align='right' style='font-weight:bold;padding-right:25px'>TOTAL</td><td align='right'>S/.  ".number_format($total,2,'.',',')."</td>
  105.                          <td align='center'>
  106.                          <input type='image' title='Recalcular Orden' src='http://192.168.40.100/pruebajax/public/img/refrescar.png' style='border:0px'
  107.                          onclick='recalcular()' /></td>
  108.                          </tr></table><br/>
  109.                          <div align='center'><a href='http://192.168.40.100/pruebajax/public/orden/grabar' style='text-decoration:none'>
  110.                          <img src='http://192.168.40.100/pruebajax/public/img/icono_compras.gif' style='border:0px' />
  111.                          <b style='color:#D82729'>&nbsp;&nbsp;Finalizar Compra</b></a></div>";
  112.            
  113.             echo $tabla;   
  114.     }
  115.    
  116.    
  117.     public function recalculoAction(){
  118.         $this->orden = new Zend_Session_Namespace('orden');
  119.        
  120.         $cantidad = $this->_getParam('cantidad');
  121.        
  122.         for($i=1;$i<= $this->orden->cont;$i++){
  123.             if($cantidad[$i] != $this->orden->cantidad[$i]){
  124.                 $this->orden->cantidad[$i] = $cantidad[$i];
  125.             }
  126.         }
  127.         $this->_redirect('producto/listar');
  128.     }
  129.    
  130.     public function grabarAction(){
  131.         $this->orden = new Zend_Session_Namespace('orden');
  132.         $ordenes = new Model_DbTable_Orden();
  133.         $res = $ordenes->grabar();
  134.         $this->logger->log("respuesta ".$res,Zend_Log::INFO);
  135.         //$this->_redirect('producto/listar');
  136.     }
  137. }

Gracias por su ayuda

Última edición por alfcm; 29/12/2010 a las 07:26