我是Codeigniter的新手,这是我第一次遇到这个问题。我有一个项目,有许多模型,控制器和多级视图。全部,但我的一个控制器不工作。我会尽力解释我的问题。
假设我有控制器A和控制器B.
从视图链接访问每个控制器:
//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
<div class="wrapper wrapper-content"><?php $this->load->view($contentpage); ?></div>
$配置
$config['base_url']= "http://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);
myproject中的.htaccess /
<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>
myproject / application中的.htaccess
<IfModule authz_core_module>Require all denied</IfModule>
<IfModule !authz_core_module>Deny from all</IfModule>
注意:
答案 0 :(得分:0)
如果您的localhost运行良好,则问题的主要原因是控制器名称ConA
或ConB
。类名从Capital关键字开始。请重命名Controller类并将文件另存为Cona.php
。也许它有效。有时这个问题会产生很多错误。首先,试试这个。您的网址也应全部为小写字母。您可以编写锚标记,例如, :
<a href="<?php print base_url('conb/user2'); ?>">TEST2</a>
答案 1 :(得分:0)
请在您的实时服务器的php.ini文件中启用mod_rewrite