Reputation: 222
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
Upvotes: 0
Views: 38
Reputation: 8964
It looks like you don't need routes. If they are removed, and assuming the controller is named pages
, you can call the methods like so
http://example.com/pages/show_create
and
http://example.com/pages/create
If you truly want to show the form by accessing news/show_create
then $route
in Girraj's answer is the way to go.
$route['news/show_create'] = 'pages/show_create';
Upvotes: 0
Reputation: 4033
try this:
$route['news/show_create']='Controller_name/method_name';
Upvotes: 0
Reputation: 11
Codeigniter documentation is very easiest programming documentation. You can easily learn more about routing by using following link.
https://www.codeigniter.com/userguide3/general/routing.html
As i can see in your code you don't need to mentioned method type along with route.
Here i am assuming that you have got and PagesController class where you have created a method by using name show_create and for this you can set routing like below in your route class.If still you have confusion you can write here.
$route['news/show_create'] = 'pages/show_create';
Upvotes: 1
Reputation: 233
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';
Upvotes: 0