0
I have a program made in PHP with codeIgniter. In my controler I have two methods, put in the file Routes.php so $route['default_controller'] = 'carta';
, calls the index() function. However $route['default_controller'] = 'carta/elemento';
, it calls the element() method. However, I want to call the element() method not as default, but by url. I have tried $route['elementos'] = 'carta/elementos';
, but when I try to access returns to the home page.
Controller: `
public function __construct() {
parent::__construct ();
$this->load->helper("url");
$this->load->model ( "carta_model" );
}
public function index() {
$dados = array("nome" => "Hugo") ;
$this->load->view("cartas/carta_view.php", array("dados" => $dados));
}
public function elementos() {
$elementos = $this->carta_model->getElementos();
$this->load->view("cartas/carta_view.php", array("elementos" => $elementos));
}
} ?>`
Routes.php:
$route['default_controller'] = 'carta';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
$route['elementos'] = 'carta/elementos';
model:
<?php
class carta_model extends CI_model {
public function getElementos() {
return $this->db->get("elemento")->result_array();
}
} ?>
view:
<?php echo json_encode($dados);?>
file . htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]