2017-04-27 222 views
1

我發現我的路由根本不起作用,當我輸入它表示'找不到對象'的路由時。它默認加載索引函數,並且工作,但路由不會。CodeIgniter路由不起作用

路線:

$route['default_controller'] = 'personeelcontroller'; 
$route['personeelcontroller/editPersoon'] = 'maincontroller/editPersoon'; 
$route['404_override'] = ''; 
$route['translate_uri_dashes'] = FALSE; 
$route['personeelcontroller/onInit'] = 'personeelcontroller/onInit'; 
$route['personeelcontroller/index'] = 'personeelcontroller/index'; 

控制器:

class PersoneelController extends CI_Controller 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->load->model('PersoneelModel'); 
     $this->load->model('ProjectModel'); 
     $this->load->helper('url_helper'); 
    } 

    public function index(){ 
     $data['personeel'] = $this->PersoneelModel->getPersonen(); 
     $this->load->helper('form'); 
     $this->load->library('form_validation'); 
     $this->load->view('urls/home' , $data); 
    } 

    public function onInit() 
    { 
     $data['projecten'] = $this->ProjectModel->GetProjecten(); 
     $this->load->view('urls/projects' , $data);// laad deze view wanneer methode wordt opgeroepen 
    } 

    public function editPersoon(){ 
     $this->load->helper('form'); 
     $this->load->library('form_validation'); 

     $this->form_validation->set_rules('id', 'Id', 'required'); 
     $this->form_validation->set_rules('name', 'Name', 'required'); 

     if ($this->form_validation->run() === FALSE) 
     { 
      $this->load->view('urls/failed'); 
     } 
     else 
     { 
      $this->PersoneelModel->editPersoon(); 
      $this::index(); 
     } 
    } 
} 
+0

*注意:您的命名你的類錯在這裏閱讀* http://www.codeigniter.com/user_guide/general/styleguide。 html#文件命名 – user4419336

+0

像'$ route ['default_controller'] ='personeelcontroller'的路由;' – user4419336

+0

對不起,這是一個錯字。如果這是錯誤的,它不會執行返回視圖的索引方法。 @ wolfgang1983 – BrianM

回答

0

檢查是否有在根任何.htaccess文件。如果不加.htaccess文件 和.htaccess文件中寫入以下代碼

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