Confusing of CodeIgniter routes

1233 views php
6

This is my route:

$route['pages/show_create']['GET'] = 'pages/show_create';
$route['pages/create']['POST'] = 'pages/create';

And this is my controller:

public function show_create()
    {
        $data['title'] = 'Create new news';     
        $this->load->view('templates/header', $data);
        $this->load->view('news/create');
        $this->load->view('templates/footer');
    }

    public function create()
    {
        $data['title'] = 'Create new news';
        $this->form_validation->set_rules('title', 'Title', 'required');
        $this->form_validation->set_rules('text', 'Text', 'required');
        if($this->form_validation->run() === FALSE)
        {
            $this->load->view('templates/header', $data);
            $this->load->view('news/create');
            $this->load->view('templates/footer');
        }
        else
        {
            $this->news_model->set_news();
            $this->load->view('news/success');
        }
    }

I want to show the form by accessing news/show_create route but it just return 404. What's wrong with my code? Thanks

answered question

Please remove ['get'] from route. Just use $route['pages/show_create'] = 'pages/show_create';

1 Answer

6

Add this to your routes.

$route['news/show_create']['GET'] = 'pages/show_create';

I assumed your controller name is PageController.

This is the format.

$route['desired_route']['method'] = 'controller_name/function';

posted this

Have an answer?

JD

Please login first before posting an answer.

Ads

Categories