phpmodel-view-controllerzend-frameworkzend-controller

Calling Action Of Controller Through onchange of Select But Not Through Ajax (Zend Framework)


i have a html select with options in my views .onchangei want to invoke action of my controller. Important: i am not going to do this through Ajax because onchange my whole module is changing so i want to refresh a page each time onchange.

                   <select id="p_s">
                   <?php  foreach($this->active_services as $row){ ?>
                    <option value="<?php echo $row['ph_id'];?>"><?php echo $row['ph_name'];?></option>
                      <?php }?>
                    </select> 

the action i am calling also included the below code so i am not going to do it through ajax.

            if(!$this->_request->isXmlHttpRequest()){
             //The request was not  made with JS XmlHttpRequest
              $user = new Zend_Session_Namespace('user');
              $user_id =$user->user_id;  
              $object   = new Services();
              $active_services     = $object->Get_Current_User_Active_Services($user_id);
              $this->view->assign('active_services',$active_services );
            }

the action i am calling is invoking through both ajax and normal this time i am calling it normal. Any idea would be helpful.


Solution

  • <select id="p_s">
        <?php foreach($this->active_services as $row) : ?>
            <option value="<?php echo $this->url(array(
                    "module" => "yourModule",
                    "controller" => "yourController",
                    "action" => "yourAction",
                    "p_s" => $row['ph_id']
                ),
                $yourRouteName=null,
                $reset=true); 
                ?>
             ">
                <?php echo $row['ph_name'];?>
            </option>
        <?php endforeach ?>
    </select>
    

    Then

    $("#p_s").change(function() {
        window.location.href = $(this).val();
    });