2013-08-02 3 views
0

그래서 내 zend 프레임 워크 응용 프로그램과 메신저 성공을 표시하기 위해 뷰 sucess var를 true로 설정하려고합니다. 는 나의 choosetags.phtml 필자에, 사용자 프레스 내가 데이터베이스에 데이터를 저장합니다이 작업에, 그것은/rondas/saveronda에 아약스 호출을 데이터를 전송할 때이다른 동작에서 뷰 매개 변수를 설정하십시오.

<script language = "Javascript"> 
    $(document).ready(function() { 
    $("#button").click(function() { 
     var param1 = 'first'; //or get value from some DOM element 
     var param2 = 'second'; //or get value from some DOM element 

     $.ajax({ 
     url: '/rondas/saveronda', 
     type: 'POST', 
     data: {param1: param1, param2:param2 }, 
     datatype: "json" 

}); 

    }); 
}); 

</script> 
<?php if($this->success): ?> 
    <div class="albox succesbox" style="z-index: 690;"> 
     <b>Sucesso :</b> A Palavra-passe foi alterada com sucesso. 
    </div> 
<?php endif; ?> 

<?php if($this->hasError): ?> 
    <div class="albox errorbox" style="z-index: 690;"> 
     <b>Erro :</b> <?php echo $this->errorMessage; ?> 
    </div> 
<?php endif; ?> 
<div class="simplebox grid740" style="z-index: 500;"> 
    <div class="titleh" style="z-index: 400;"> 
     <h3>Criar Ronda</h3> 
    </div> 
    <div class="body" style="z-index: 380;"> 



    <script type="text/javascript"> 
    var t=0; 
    $(function(){ 

      $("#toolbar").jqGrid({ 
       caption:"Tags", 
       colNames:['ID','Nome','Cliente','Descrição','Modo','Estado'], 
       colModel:[ 

        {name:'id_tag',index:'id_tag',hidden:true}, 
        {name:'tag_nome',index:'tag_nome'}, 
        {name:'nome',index:'nome'}, 
        {name:'descricao',index:'descricao'}, 
        {name:'modo',index:'modo'}, 
        {name:'estado',index:'estado'} 


       ], 
       datatype:"json", 
       height:421, 
       rownumWidth:40, 
       pager:'#ptoolbar', 
       rowList:[10,20,30], 
       rowNum:10, 
       sortname:'id_tag', 
       sortorder:'desc', 

       viewrecords:true, 
       width:700 
      }); 
      $("#toolbar").jqGrid('navGrid','#ptoolbar',{del:false,add:false,edit:false,search:false}); 
      $("#toolbar2").jqGrid({ 
       caption:"Tags da Ronda", 
       colNames:['ID','Nome','Cliente','Descrição','Modo','Estado'], 
       colModel:[ 
        {name:'id_tag',index:'id_tag',hidden:true}, 
        {name:'tag_nome',index:'tag_nome'}, 
        {name:'nome',index:'nome'}, 
        {name:'descricao',index:'descricao'}, 
        {name:'modo',index:'modo'}, 
        {name:'estado',index:'estado'} 


       ], 
       datatype:"json", 
       height:421, 
       rownumWidth:40, 
       pager:'#ptoolbar2', 
       rowList:[10,20,30], 
       rowNum:10, 
       sortname:'id_tag', 
       sortorder:'desc', 

       viewrecords:true, 
       width:700 
      }); 
      $("#toolbar2").jqGrid('navGrid','#ptoolbar2',{del:false,add:false,edit:false,search:false}); 
      $("#toolbar").jqGrid('gridDnD',{connectWith:'#toolbar2',dragcopy:true,beforedrop: function (ev, ui, getdata, $source, $target) { 
     var names = $target.jqGrid('getCol', 'id_tag'); 

     if ($.inArray(getdata.id_tag, names) >= 0) { 
      // prevent data for dropping 
      ui.helper.dropped = false; 
      alert("A tag ja existe na ronda"); 

     } 
    else 
     { 

      document.getElementById("tagini").innerHTML= document.getElementById("tagini").innerHTML +"<option value="+getdata.id_tag+">"+getdata.tag_nome+','+getdata.nome+','+getdata.descricao+','+getdata.modo+"</option>"; 
document.getElementById("tagfim").innerHTML= document.getElementById("tagfim").innerHTML +"<option value="+getdata.id_tag+">"+getdata.tag_nome+','+getdata.nome+','+getdata.descricao+','+getdata.modo+"</option>";  }}}); 

    }); 

    $(function(){ 
     // Attach the dynatree widget to an existing <div id="tree"> element 
     // and pass the tree options as an argument to the dynatree() function: 
     $("#tree").dynatree({ 
      initAjax: { 
     url: "/locais/tree" 
     }, 
     onActivate: function(node) { 
     t=node.data.key; 
     if(t!=0) 
     { 

     $("#echoActive").text(node.data.title); 
     $("#tables").show(); 
     $("#toolbar").jqGrid('setGridParam',{url:"/rondas/choosetags/id/"+t}).trigger("reloadGrid"); 
     reloadGrid(); 


     } 
     else 
     {   
     $("#echoActive").text("-");  
     $("#tables").hide(); 

     } 

     } 
     }); 


    }); 


    </script> 
    <div class="st-form-line" style="z-index: 680;"> 
<span class="st-labeltext">Escolher a localização:</span> 
<div id="tree" > </div> 


<div class="clear" style="z-index: 670;"></div> 
</div> 
<!-- Add a <div> element where the tree should appear: --> 
<div class="st-form-line" style="z-index: 680;"> 
<span class="st-labeltext">Localização:<span id="echoActive">-</span></span> 
<div id="tables" style="display:none" > 


    <table id="toolbar"></table> 
    <div id="ptoolbar"></div> 
    </div> 

<div class="clear" style="z-index: 670;"></div> 
</div> 

<div class="st-form-line" style="z-index: 680;"> 
<span class="st-labeltext">Tags da ronda:</span> 



    <table id="toolbar2"></table> 
    <div id="ptoolbar2"></div> 


<div class="clear" style="z-index: 670;"></div> 
</div> 

<div class="st-form-line" style="z-index: 680;"> 
<span class="st-labeltext">Nome da ronda:</span> 

    <input type="text" name="nomeronda" id="nomeronda"> 




<div class="clear" style="z-index: 670;"></div> 
</div>  
<div class="st-form-line" style="z-index: 680;"> 
<span class="st-labeltext">Tag Inicial:</span> 


<select id="tagini" name="tagini"> 
</select> 
<div class="clear" style="z-index: 670;"></div> 
</div> 
<div class="st-form-line" style="z-index: 680;"> 
<span class="st-labeltext">Tag Final:</span> 


<select id="tagfim" name="tagfim"> 
</select> 
<div class="clear" style="z-index: 670;"></div> 
</div> 
<div class="st-form-line" style="z-index: 680;"> 
<span class="st-labeltext">Ordem:</span> 


<select id="ordem" name="ordem"> 
    <option value="Sim">Sim</option> 
    <option value="Não">Não</option> 
</select> 
<div class="clear" style="z-index: 670;"></div> 
</div> 
<div class="button-box" style="z-index: 460;"> 
<input id="button" class="st-button" type="submit" value="Submit" name="button"> 
<input id="button2" class="st-clear" type="reset" value="Cancel" name="button"> 
</div> 

</div> 
    </div> 

그래서 사용자가 선택할 수 있어요 내가/rondas/chooserondas로 리디렉션하고 성공 메시지를 표시 할이가 성공하면하고, 내가 어떻게 이것을 달성 할 수 있습니다 .. 그래서 여기에/rondas/saveronda

public function saverondaAction() 
    { 
     // action body 

      $this->_helper->layout()->disableLayout(); 
      $this->_helper->viewRenderer->setNoRender(true); 
      if($this->_request->isXmlHttpRequest()) 
     { 


     $param1 = $this->_request->getParam('param1'); 
$param2 = $this->_request->getParam('param2'); 
//save data on the db and return to the /rondas/choosetags and display sucess message.   
      } 

    } 

의 코드이며, 여기 있습니다/rondas/choosetags에 대한 코드

public function choosetagsAction() 
    { 



     // action body 
     if($this->_request->isXmlHttpRequest()) 
     { 
      $request= $this->getRequest(); 
      $poll_id = $request->getParam('id'); 
      $this->_helper->layout()->disableLayout(); 
      $this->_helper->viewRenderer->setNoRender(true); 

      Zend_Paginator::setDefaultScrollingStyle('Sliding'); 
      $page = $this->_getParam('page', 1); 
      $limit = $this->_getParam('rows', 0); 
      $sidx = $this->_getParam('sidx', 1); 
      $sord = $this->_getParam('sord', 0); 
      $totalrows = $this->_getParam('totalrows', false); 
      if($totalrows) 
       $limit = $totalrows; 
      $tableModel = new Application_Model_Tags(); 
      $select = $tableModel->select(); 
      $select->setIntegrityCheck(false); 
      $select->from('tags', array('id_tag','tag_nome', 'id_software', 'id_hardware','id_localizacao','descricao','modo','estado'))->joinInner('clientes', 'tags.id_cliente = clientes.id_cliente', array('nome'))->where('id_localizacao='.$poll_id); 
      $filters = !empty($_REQUEST['filters']) ? (array) json_decode($_REQUEST['filters']) : array(); 

      $adapter = new Zend_Paginator_Adapter_DbTableSelect($select); 
      $paginator = new Zend_Paginator($adapter); 
      $paginator->setCurrentPageNumber($page)->setItemCountPerPage($limit); 
      $count = $paginator->getTotalItemCount(); 
      $total_pages = $count > 0 ? ceil($count/$limit) : 1; 
      $responce = new stdClass(); 
      $responce->page = $page > $total_pages ? $total_pages : $page; 

      $responce->total = $total_pages; 
      $responce->records = $count; 
      $i = 0; 
      foreach($paginator as $item) 
      { 
       $responce->rows[$i]['id'] = $item['id_tag']; 

      $responce->rows[$i]['cell'] = array($item['id_tag'],$item['tag_nome'],$item['nome'],$item['descricao'],$item['modo'],$item['estado']); 
       $i++; 
      } 
      echo json_encode($responce); 

     } else 
     { 
      $this->_helper->layout()->pageTitle = 'Rondas'; 
      $this->_helper->layout()->pageDescription = 'Criar as rondas'; 
     } 

    } 

동일한 동작과보기를하고 있다면 메시지를 표시 할 수 있습니다. 즉,이 $ this-> view-> sucess = true, 성공 메시지 apperas를 넣으면/rondas/choosetags에 있습니다. action/rondas/saveronda에서 success 변수를 true로 설정하고 action/rondas/tags를 선택하고 성공 메시지를 표시하려고합니다.

답변

0

직접하실 수 없습니다.

$hopSession = new Zend_Session_Namespace('tempViewParams'); 
$hopSession->my_view_param1 = 'string with data'; 
$hopSession->setExpirationHops(1); 

당신보다 임시 세션에서 값을 얻을 수 있습니다 : 당신이 할 수있는 것은 (1 홉 = 1 개 성공적인 요청 예를 들어,의 만료와 함께) 임시 세션에서 설정하려는 PARAMS을 저장할 수있다 다음 행동에서 또 다른 방법은 성공적인 저장시 리디렉션 할 url에서 매개 변수로 설정하려는 뷰 값을 추가하는 것입니다 (특히이 경우 원하는 모든 값이 true 매개 변수 인 경우). 그래서 같은 URL : 당신이 SESSION 솔루션은 가장 아름다운 것이 여러 PARAMS를 통과 할 경우에 물론

if(1 == $request->getParam('success'))({ 
    $this->view->success = true; 
} 

:

/rondas/choosetags/sucess/1 

그래서 당신처럼 choosetagsAction()에 무언가를 추가 할 수 있습니다 .

+0

답장을 보내 주셔서 감사합니다. 신청서를 통해 동일한 URL을 유지할 수있는 방법이 있습니까? 왜냐하면 나는 어떤 매개 변수가 보내지는지를 사용자가보고 싶지 않기 때문이다. –

+0

아니요,하지만 이것이 문제가된다면 세션 해결책을 제안 할 것입니다. – RMK

+0

매개 변수 expirationhops의 마이닝은 리디렉션 동안 만 유지된다는 의미입니까? 리디렉션이 완료되면 $ hopsession이 삭제됩니다. –

관련 문제