我正在建立一個CodeIgniter項目,到目前爲止一切進展順利。除了一個之外,我的所有路線和控制器都能正常工作。雖然我是CodeIgniter的新手,但我已經使用PHP進行了近五年的編程,所以我有一些經驗。如果有人可以看看下面的代碼示例,並讓我知道我做錯了什麼,那會很好。Codeigniter 3路由不工作
很明顯,該應用程序確實識別該路由,但它一直抱怨無法找到該URI。
控制器:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Profile extends CI_Controller {
function __construct() {
parent::__construct();
$this->load->helper('url');
}
public function Profile($page = 'profile-page')
{
if (! file_exists(APPPATH.'/views/'.$page.'.php'))
{
// Load error page
show_404();
}
// Capitalize the first letter
$data['title'] = ucfirst($page);
$data['pageType'] = "profile-page";
// Load pages
$this->load->view('templates/header', $data);
$this->load->view('templates/topbar', $data);
$this->load->view('profile');
$this->load->view('templates/footer', $data);
//
}
}
接下來是我的路線:
$route['default_controller'] = 'home/home';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
// All custom routes go below this line.
$route['contact'] = 'pages/contact';
$route['signup'] = 'auth/signup';
$route['login'] = 'auth/login';
$route['profile'] = 'profile/profile';
我已經驗證了所有的視圖文件是在正確的文件夾,並沒有錯別字。然而配置文件路線仍然失敗。所有其他路徑正常工作,除了配置文件路由。
我在Windows 10上用XAMMP,Mac OS X Sierra與MAMP和CentOS 7與Apache/PHP/MySQL一起嘗試了這一點。
謝謝。
雖然不是我的問題的答案,但您的問題確實指向了正確的方向。我得到它的工作原來是一個丟失的文件。 –