简体   繁体   中英

page not found error in codeigniter

I have anchor in header.php as below:

<a href="<?php base_url();>backend">Backend</a>

Also have the controller named backend.php in Controllers folder.

I also routed this code in routes.php file like

$route('default_controller')='frontend';
$route('backend')='backend';

Backend controller page is:

<?php 
class Backend extends CI_Controller { 
          public function __construct(){ 
                  parent::__construct(); 
         } 
         public function index(){ 
             $data['title'] = 'Backend Page'; 
             $this->load->view('templates/header', $data); 
             $this->load->view('backend/reg', $data); 
             $this->load->view('templates/footer'); 
       } 
}

Although getting error 404 Page not found.

Try this one :

<a href = "<?php echo base_url();?>/pathforyourbackend">Backend </a> // include also the folder where your backend file is stored

I hope this helps.

Make sure all controller and models etc Ucfirst example Frontend.php instead of frontend.php

Codeigniter Docs http://www.codeigniter.com/docs

Auto load url helper in application.config/autoload.php

Change route from

$route('default_controller') ='frontend';

to

$route['default_controller'] = "frontend";

$route['backend'] = "backend";

I you have not set up you config to remove index.php with htaccess then use index.php in link.

<a href="<?php echo base_url('index.php/backend');">Backend</a>

Example controllers/Backend.php

<?php 

class Backend extends CI_Controller { 
public function __construct(){ 
parent::__construct(); 
} 
public function index(){ 
$data['title'] = 'Backend Page'; 
$this->load->view('templates/header', $data); 
$this->load->view('backend/reg', $data); 
$this->load->view('templates/footer'); 
} 
}

Example controllers/Frontend.php

<?php 

class Frontend extends CI_Controller { 
public function __construct(){ 
parent::__construct(); 
} 
public function index(){ 
$data['title'] = 'Frontend Page'; 
$this->load->view('templates/header', $data); 
$this->load->view('frontend/reg', $data); 
$this->load->view('templates/footer'); 
} 
}

Link here for htaccess examples for removing index.php on windows os https://github.com/riwakawebsitedesigns/htaccess_for_codeigniter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM