主要控制器问题

时间:2011-08-13 19:13:53

标签: php codeigniter

我不知道为什么,但是我上传了一个新版本的CI,我的主控制器无法正常工作,也不确定原因。

http://www.kansasoutlawwrestling.com/kowmanager

编辑:有什么想法吗?

编辑2:

控制器:(kowmanager.php)

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

class Kowmanager extends CI_Controller {

public function __construct()
{
    $this->load->helper('url');
    $this->load->library('tank_auth');
    parent::__construct();

}

function index()
{
    if (!$this->tank_auth->is_logged_in()) {
        redirect('/auth/login/');
    } else {
        $data['user_id']    = $this->tank_auth->get_user_id();
        $data['username']   = $this->tank_auth->get_username();
        $this->load->view('welcome', $data);
    }
}

}

/* End of file kowmanager.php */
/* Location: ./application/controllers/kowmanager.php */

的.htaccess

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

### Canonicalize codeigniter URLs

# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(kowmanager(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]


# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]

# Enforce www
# If you have subdomains, you can add them to 
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]

# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]

###

# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

</IfModule>

<IfModule !mod_rewrite.c>

# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php

</IfModule>

配置

http://pastebin.com/9ZCpQNJj

编辑:

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

class Kowmanager extends CI_Controller {

public function __construct()
{
    parent::__construct();
    $this->load->library('tank_auth');
    $this->load->library('template');
    echo CI_VERSION;

}

function index()
{
    if (!$this->tank_auth->is_logged_in()) {
        redirect('/auth/login/');
    } else {
        $data['user_id']    = $this->tank_auth->get_user_id();
        $data['username']   = $this->tank_auth->get_username();
        $this->load->view('welcome', $data);
    }
}

}

/* End of file kowmanager.php */
/* Location: ./application/controllers/kowmanager.php */

2 个答案:

答案 0 :(得分:3)

这是服务器404,而不是Codeigniter - 因此它与CI或CI配置无关。

您的.htaccess文件必定存在问题,请确保通过index.php路由所有相应的请求。

如果这应该是您的默认控制器,那么当我查看http://www.kansasoutlawwrestling.com时您会遇到另一个问题:

  

遇到错误

     

要使用Session类,您需要设置一个   配置文件中的加密密钥。

我希望不言自明。


  

我用这个http://farinspace.com/codeigniter-htaccess-file制作了我的htacess文件

我不确定是否所有这些都是必要的,但是你读过这部分吗?

# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
  

只要加密密钥是自我解释的,但不确定要为它添加什么。

我认为你需要熟悉docs,听起来你自己并没有做任何努力。实际上,加密密钥信息完全覆盖在配置文件本身的注释中。

答案 1 :(得分:1)

尝试:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

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