2017-01-11 84 views
0

我无法访问我的控制器中的其他功能,直到我将index.php?添加到url。我可以直接访问任何控制器的index()功能,但不能访问其他功能。我检查了其他相关问题,但问题仍然存在。我也尝试将所有控制器添加到routes.php但仍然失败。无法访问控制器Codeigniter的其他功能

HTACESS

RewriteEngine on 
RewriteCond $1 !^(index\.php|images|css|js|include|style\.css|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

CONFIG

$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 
$config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . preg_replace('@/[email protected]', '', dirname($_SERVER['SCRIPT_NAME'])) . '/'; 

$config['base_path'] = $_SERVER['DOCUMENT_ROOT'] . preg_replace('@/[email protected]', '', dirname($_SERVER['SCRIPT_NAME'])) . '/'; 

BLOG控制器

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

class Blog extends CI_Controller { 

    function __construct() 
    { 
     parent::__construct(); 
     $this->load->database(); 

    } 

    public function index() 
    { 
     $data['page_name'] = 'blog'; 
     $this->load->view('pages/index', $data); 
    } 

    public function news() 
    { 
     $data['page_name'] = 'news'; 
     $this->load->view('pages/index', $data); 
    } 
} 

URL

http://localhost/tsb/blog // This works fine 
    http://localhost/tsb/blog/news // only works when i add index.php? to the url 

回答

1

你需要检查你的CSS和JS包括正确。确保使用绝对网址。从你的问题,你似乎通过一个索引文件中加载所有的意见(页)的文件夹

你的资产或资源链接应该是这样的

<link rel="stylesheet" type ="text/css" src="<?php echo base_url();?>css/style.css" /> 

做同样的JavaScript或其他资产

$config['base_url'] = 'http://localhost/tsb/'; 

$config['index_page'] = ''; 

$config['uri_protocol'] = 'REQUEST_URI'; 

的.htaccess

RewriteEngine on RewriteCond $1 !^(index\.php|images|css|js|include|style\.css|robots\.txt) RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php/$1 [L] 

这样,所有的页面将负荷p roperly包括你的控制器中的所有功能

+0

谢谢你是这个问题 – Mysterio4

0

打开config.php文件,并做以下内容替换

$config['index_page'] = "index.php" 

$config['index_page'] = "" 

只需更换

$config['uri_protocol'] ="AUTO" 

$config['uri_protocol'] = "REQUEST_URI" 

变化从

$config['base_url'] = 'http://localhost/tsb/'; 

$config['base_url'] = (isset($_SERVER['HTTPS']) ? "https://" : "http://") . $_SERVER['HTTP_HOST'] . preg_replace('@/[email protected]', '', dirname($_SERVER['SCRIPT_NAME'])) . '/'; 

$config['base_path'] = $_SERVER['DOCUMENT_ROOT'] . preg_replace('@/[email protected]', '', dirname($_SERVER['SCRIPT_NAME'])) . '/'; 

及其在htaccess文件就把下面的代码

RewriteEngine on 
RewriteCond $1 !^(index\.php|resources|robots\.txt) 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 
+0

我试过你粘贴,但它不工作 – Mysterio4

+0

更新你的问题,并把你所做的所有文件 –

+0

我做了更新,因为你指导,但仍然失败。我现在就开始新的安装 – Mysterio4

0

找到以下:

打开config.php文件,并做以下内容替换

$config['index_page'] = "index.php" 

$config['index_page'] = "" 

在某些情况下,uri_protocol默认设置无法正常工作。只需更换

$config['uri_protocol'] ="AUTO" 

$config['uri_protocol'] = "REQUEST_URI" 

这会从您的网址中删除的index.php,你可以访问页面,方法等没有的index.php

相关问题