Error redirecting internal pages with codeigniter

0

Good evening. My question is the following, I have a menu and in it several options I created a VIEW called queryProducts and I would like that when clicking on query the same was for this screen, but this does not happen, like redirecting pages using the codeigniter since the same uses MVC, below follows image of how the structure is.

Example of how the menu is currently .. Note: I already tried to use base_url without success.

 <ul class="dropdown-menu">
 '<li><a href="consultaProdutos.php">Consulta</a></li>'
 '</ul>'
    
asked by anonymous 24.10.2016 / 02:57

1 answer

1

You should not access the view queriesProducts.php directly though it is possible, but this is not how it works in MVC and in this case in CodeIgniter as well.

Ideally in the view file consultaProdutos.php there should be the following statement to deny direct access:

defined("BASEPATH") or exit("Acesso direto negado");

You should first create a Controller for products, then create a function to load that view.

class Produto extends CI_Controller {
   public function consultaProdutos(){
     // consultaProdutos abaixo é o nome da view
     $this->load->view("consultaProdutos");
   }
}

Your link will be thus used the URL Helper:

<a href="<?=site_url("produtos/consultaProdutos") ?>">Consulta</a>

The produtos indicates the Controller, and the consultaProdutos indicates the action name.

To load this helper use the following code or configure it to load autoload.php:

$this->load->helper('url');

You could also use the following link (less recommended)

<a href="index.php/produto/consultaProdutos">Consulta</a>
    
25.10.2016 / 14:04