Problem accessing a controller in CODEIGNITER php

Asked

Viewed 332 times

0

I have a View with a nav-link:

href= echo base_url("application/controllers/Login_controller.php") 

By clicking I am redirected to the correct path.

http://localhost/local/acjum1/application/controllers/Login_controller.php

However, a message appears saying "No direct script access allowed".

This is my class Login_controller

<?php
defined('BASEPATH') OR exit ('No direct script access allowed');

class Login_controller extends CI_Controller {

    public function index()
    {
        $this->load->view("login/Login_view");                  
    }
}

What’s wrong with it?

  • it is complicated to answer, you have to read the documentation because your mistake is in all codes.

1 answer

0


Hello! All files in the directory /application should only be accessed by the Codeigniter framework. So much so that they contain, in the first line, the following code, from which comes the message displayed to you:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

You cannot, nor is there any logical reason to do so, referencing views, controls and models directly. To access your login page, use the link that is mounted as follows:

href="<?=site_url('login_controller')?>"

This throws you right into the index( ).


I suggest further, rename this control only to Login, because the word "controller" is appearing unnecessarily in the URL. You know that this is a control because the file will be in the directory /application/controllers.

Already the view Login_view used in the function index( ), I suggest renaming to only index. You know she’s a view because she’ll be in the directory /application/views. So you close a link between all the existing controls in which your views will be in the directory that has the name of the given control and the name of the view to be loaded in the function will have the name of the function itself.

Browser other questions tagged

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