Check with where in CodeIgniter

0

I am trying to make a query in which you show me an article in this library using the uri library

In the index I show a list of courses, if I click on a course through the recovered id I want to show only that course individually.

shows me all the courses but does not show me the individual.

As you can see, the url does change with respect to the id retrieved from the query. this is my controller

function index(){
        $data['segmento'] = $this->uri->segment(3);
        $this->load->view('codigoFacilito/headers');
        if(!$data['segmento']){
            $data['cursos'] = $this->codigofacilito_model->obtenerCursos();
        }
        else{
            $data['cursos'] = $this->codigofacilito_model->obtenerCurso($data['segmento']);
        }
        $this->load->view('cursos/cursos', $data);
    }

This is my model

function obtenerCurso($id){
        $this->db->where('idCurso', $id);
        $query = $this->db->get('cursos');
        if($query->num_rows()>0){
            return $query;
        }
        else{
            return false;
        }
    }

This is my view

<?php
    if($cursos){
        foreach ($cursos->result() as $curso) {
 ?>
        <ul>
            <li><a href="<?= $curso->idCurso ?>"><?= $curso->nombreCurso ?></a></li>
        </ul>
<?php
        }
    }
    else{
        echo "<p>Error en la aplicación</p>";
    }
?>
</body>
</html>

greetings and thanks for your help

    
asked by Dani Vil 07.07.2018 в 07:03
source

1 answer

0

Test your routes, because you may not be indicating that this function in the controller will receive parameters through the url

example:

$ route ['miruta / (: any)']="controller / function_controller / $ 1";

That way you should work without problems, the rest seems that you are doing well.

    
answered by 14.07.2018 в 10:33