0

so im my zend framework aplication and im trying to set the view sucess var to true in order to show a sucess messega. so in my choosetags.phtml ive got this

<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>

so the user choose when the user press submit data it makes an ajax call to /rondas/saveronda, in this action i will save the data on the database, and once it succeds i want to redirect to the /rondas/chooserondas and show a sucess message, how can i achieve this.. so here is the code for the /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.          
             }

    }

and here is the code for the /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';
        }

    }

i can show the message if i am on the same action and view , i mean , in the /rondas/choosetags if i put this $this->view->sucess=true, the success message apperas, but i want to set the success var to true in action /rondas/saveronda and then redirect to the action /rondas/choose tags and show success message.

4

1 回答 1

0

You can't directly. What you can do is save the params you want to set in a temporary session (with a expiration of, for example, 1 hop = 1 successful request):

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

You can than get the values from your temporary session in the next action. Another way is to add the view values you want to set as params in the url you're redirecting to on a successful save (especially in this case where all you want is a true param). So an url like:

/rondas/choosetags/sucess/1

So you can add something to your choosetagsAction() like:

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

Of course in case you want to pass through multiple params the SESSION solution would be the most beautiful.

于 2013-08-03T14:55:32.900 回答