2017-01-11 86 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

相關問題