CodeIgniter路由不起作用

时间:2017-04-27 08:21:01

标签: php codeigniter url routing routes

我发现我的路线根本不工作,当我输入路线时说“找不到物体”。它默认加载索引函数并且有效,但路由不会。

路线:

$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();
        }
    }
}

1 个答案:

答案 0 :(得分:1)

检查root中是否有.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]