How to receive codeigniter variables without having to load the view?

0

To edit the data of a person I have a button which when pressed takes that id and sends it not by ajax but directly to the controller with the id to make the validation and bring the data ...

What I want is for that data to show me in a modal window but with data sent directly from the php (codeigniter), normally it is used like this ...

if($answer)
{
 $data = array('nombre' => $answer->nombre_personal,
               'apellido' => $answer->apellido_personal)
 $this->load->view(index,$data);
}

It happens that since the view is already loaded in funcion index I can not reload it to show me the data, then how else could I take those without loading the view again?

PS: The use of ajax is not required ..

I would appreciate your collaboration and interest.

    
asked by JDavid 07.03.2017 в 23:31
source

1 answer

1

You can do it using jquery , creating a function in the controller where you print the content in a json, I'll give you an example:

  

In codeigniter:

public function getmodal(){

   $output = array('nombre'=>'Pedro', 'apellido'=>'Gonzales');
   echo json_encode($output);
}
  

In jquery:

path=baseurl+"controladora/getmodal"    

$.post(path, function(result){

              $(selector 1 del modal).html(result.nombre);
              $(selector 2 del modal).html(result.apellido);
            },'json');
  

For the case of the id you only have to incorporate it into the $ .post to pass it to the controller and capture it inside the function with $ this- > input-> post ();    $ .post jquery

    
answered by 11.04.2017 в 01:21