codeigniter: change from one view to another

4

I have a question, I am using codeigniter and I want to do the following, in the model I make a query which I charge in array in the index of my controller, which later I show it in a table through a foreach in the view .. my question is .. one of the things I get from the query is the code which I want it to be as link to another view, and use it as a parameter for another consult, could you help me please I'm a novice in this

<?php
  foreach($array as $fila)
  {
?>
<tr>
  <td><a href=""><?=$fila->codigo?></a></td>
  <td><?=$fila->nombre?></td>
  <td><?=$fila->fecha?></td>
  <td>
</tr>
<?php
  }
?>  

well in the model I have a simple query with select , and in the index of the controller, comment that I loaded the result of that query in a array that I then send to view and show it more or less as the code that you attach, and in the row of code I put a label to href and that code can send it to another to another view

    
asked by nanolei 20.12.2016 в 02:28
source

3 answers

0

When calling the view in the controller, you pass the variable in array format in the second parameter of the load function:

Controller:

function pagina() {
    $color = 'azul';
    $this->load->view("vista_view", array('color' => $color));
}

View:

<p>Color: <?php echo $color; ?></p>

Shown:

Color: azul
    
answered by 04.07.2018 в 15:54
0

From the view, where tu_vista should be the function of your controller.

<a href="<?php echo base_url('tu_controlador/tu_vista/'.$fila->codigo);?>"> Texto </a>
    
answered by 20.12.2016 в 03:10
0

I do not know if I finish understanding your question, but you should put the variable in the href of the link.

And $fila->codigo should have something of the form " /controller/vista/codigo ".

<?php
  foreach($array as $fila)
  {
?>
<tr>
  <td><a href="<?=$fila->codigo?>"><?=$fila->codigo?></a></td>
  <td><?=$fila->nombre?></td>
  <td><?=$fila->fecha?></td>
  <td>
</tr>
<?php
  }
?>  
    
answered by 11.07.2018 в 20:23