Method behavior with codeigniter parameters

Viewed 28

Needing help understanding codeigniter 3 behavior

I'm not understanding the controller behavior very well and I ask for help

class Simulado extends CI_Controller {

    function __construct(){

        parent::__construct();
        $this->load->helper('url');
        $this->load->helper('funcoes_helper');
        $this->load->helper('file');            
        $this->load->library('session');
        $this->load->library('controle_acesso');
        $this->load->model('resumoapp_model', 'resumo');
        $this->load->model('homeapp_model', 'homeapp');
        $this->load->model('simulado_model', 'simulado');       

        //permissão para acessar app
        $this->controle_acesso->acesso();

        $this->output->enable_profiler(TRUE);
        
    }

    public function index() { 

        $dados = '0'//todas as materias;
        $bdinsert = $this->simulado->set_bd($dados);

        $this->load->view('prova',$dados)

    }

    public function materia () { 
                        
        $dados = 1; //idamateria
        $bdinsert = $this->simulado->set_bd($dados);
        $this->load->view('prova',$dados)

    }
}

model

public function set_bd ($dados) {           

            $data = [
                'id_mat' = $dados
            ];

            $this->db->insert('simulados', $data);
    }

routes.php

$route['default_controller'] = 'home';
$route['404_override'] = 'my404';
$route['translate_uri_dashes'] = FALSE;
$route['app'] = "/app/home";
$route['site'] = "/home";

when accessed through the link http://localhost/escola/app/simulado, the system behaves in the desired way, it writes the value zero once in the database, for example.

accessing the url we have the method of the class, simulated, http://localhost/escola/app/simulado/materia/1/exatas-matematica calls the method in the correct way, but when writing to the database it writes the code of the matter.

I did a test and put the same code of the article method in the index and called the url, and it worked perfectly, writing only once the code of the article in the database.

I need to know why it is recording 3 times in the database when accessing the url is a method of the class and has parameters.

0 Answers
Related