Error redirecting internal pages with codeigniter

Asked

Viewed 708 times

0

Good night. My doubt is the following, I have a menu and in it several options I created a VIEW called Products query and I would like that when clicking on query the same was for this screen, however this does not occur, how to redirect pages using codeigniter since it uses MVC, below follows image of how this the structure.menu

Example of how this menu currently.. Note: I tried to use base_url but failed.

 <ul class="dropdown-menu">
 `<li><a href="consultaProdutos.php">Consulta</a></li>`
 '</ul>'
  • 1

    But you set up the controller to call him?

1 answer

1

You should not access the query view.php products directly although it is possible, but that is not how it works in MVC and in the case in Codeigniter as well.

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

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

You must first create a Controller for products, then create a function to load this view.

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

Your link will thus be used the URL Helper:

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

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

To load this helper use the code below or set it to auto load in autoload.php:

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

You could also use the following link (less recommended)

<a href="index.php/produto/consultaProdutos">Consulta</a>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.