1
votes

I'm new with Codeigniter and this is the first time I encounter this issue. I have a project that has many models, controllers, and multilevel views. All, but one of my controller is not working. I'll try my best to explain my issue.

Let's say I have controller A and Controller B.

Link from view to access each controller:

//This link go to Con A
<a href="<?php print base_url(); ?>ConA/user">TEST1</a>

//This link go to Con B
<a href="<?php print base_url(); ?>ConB/user2">TEST2</a>

Con A

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

class ConA extends CI_Controller
{
function __construct()
{
    parent::__construct();
    $this->load->model('MAdmin');
}

public function user()
{
   $data = array (
        'titlepage' => APP_TITLEPAGE,
        'titleapp' => 'User Management',            
        'listdept' => $this->MAdmin->get_dept(),
        'complete' => 'false',
        'contentpage' => 'admin/user');//This is the view directory. Will open user.php in myproject/application/views/admin

    $this->load->view('shared/master_app', $data);
}

Con B

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

class ConB extends CI_Controller
{
function __construct()
{
    parent::__construct();
    $this->load->model('MAdmin');
}

public function user2()
{
   $data = array (
        'titlepage' => APP_TITLEPAGE,
        'titleapp' => 'User Management',            
        'listdept' => $this->MAdmin->get_dept(),
        'complete' => 'false',
        'contentpage' => 'admin/user');//This is the view directory. Will open user.php in myproject/application/views/admin

    $this->load->view('shared/master_app', $data);
}

shared/master_app in Views

<div class="wrapper wrapper-content"><?php $this->load->view($contentpage); ?></div>

$config

$config['base_url']= "http://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

.htaccess in myproject/

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /myproject
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /myproject/index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>

.htaccess in myproject/application

<IfModule authz_core_module>Require all denied</IfModule>
<IfModule !authz_core_module>Deny from all</IfModule>

Note:

  • In offline mode (Localhost) everything is run well
  • the URL in the address bar after a redirect from the link is the same (except the naming).
2
Not an expert but I am facing problem in the beginning when I start Codeigniter, in local my all URL is running ok but on the server that create problems and didn't load. So I found that I didn't follow the naming convention of CI. So You should check that first.ankit suthar
what is the URL? Please add the access URL in your question.Nishant Nair
It seem my new controller is not registered. I solve my problem by merge the controller.Shota

2 Answers

0
votes

If your localhost working well, The main cause of an issue is controller name which is ConA or ConB . Classes name start from Capital keyword. Please rename the Controller class and save the file as Cona.php . Maybe it works. Sometimes this issue creates a lot of bugs. First, try with this. Also Your URLs should be all lowercase letters. You can write anchor tag like as , e.g. :

<a href="<?php print base_url('conb/user2'); ?>">TEST2</a>
0
votes

Please enable mod_rewrite in php.ini file of your live server