The view is not showing the parameters passed by the controller

0

Related to this question --- > > $ this- > request- > getData (); does not recover the data

I do not know why the variable $ option is not shown in the view, but success if it is showing:

<div class="modalHome">
modificar-foto-cuenta</div>

jQuery + AJAX:

$(document).on("click", "#modificar-foto-cuenta", function() {          
                var opcion = $(this).attr("id").valueOf();              
                    $.ajax({
                        type: "POST",
                        url: "/Users/home/",
                        data: "opcion = " + opcion,
                        dataType: 'html',
                        success: function (response) {           console.log(response); },
                    error: function () { alert('error'); }
                    });                 
                $('.modalHome').show();         
        });

Driver:

  public function home() {
        if($this->request->is('post')) {
          $data = $this->request->getData();
          $opcion = $data['opcion'];

        /*$session = $this->getRequest()->getSession();
          $session->write('opcion', $opcion);
          $opcion = $session->read('opcion');*/

          $this->set('opcion', $opcion);
        }
        else {
          $this->set('opcion', 'No pasa');
        }
     }

Vista:

<div class="modalHome">
   <?php echo $opcion; ?>
</div>

I've tried session , but with the same result

    
asked by Isaac Palacio 01.01.2019 в 13:49
source

1 answer

1

You must save your variable in the session so that it is accessible from any part of PHP, in this way:

public function home() {
    if($this->request->is('post')) {
      $data = $this->request->getData();
      $opcion = $data['opcion'];

      $this->Session->write('opcion', $opcion);
      //o:
      Session::write('opcion', $opcion)
    }
    else {
      $this->set('opcion', 'No pasa');
    }
 }
    
answered by 02.01.2019 в 18:52