Reputation: 516
I'm having problem with CodeIgniter 2. It's returning a 404 Error. Here is my code:
config/routes.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['default_controller'] = "inventory";
$route['404_override'] = '';
$route['create_item'] = "inventory/createitem";
controllers/inventory.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Inventory extends CI_Controller
{
public function index()
{
$this->load->view('inventory/index');
}
public function create_item()
{
$this->load->view('inventory/createitem');
}
}
views/inventory/createitem.php
<!DOCTYPE html>
<html lang="en">
<head>
<?php $this->load->view('templates/head_inc'); ?>
</head>
<body>
<?php $this->load->view('templates/header_inc'); ?>
<div class="container-fluid">
<div class="row">
<div class="col-sm-3 col-md-2 sidebar">
<ul class="nav nav-sidebar">
<li class="active"><a href="index.php">Dashboard</a></li>
<li ><a href="patients.php">Patients</a></li>
</ul>
<ul class="nav nav-sidebar">
<li ><a href="createpatient.php">Create New Patient</a></li>
</ul>
<ul class="nav nav-sidebar">
<li ><a href="reports.php">Reports</a></li>
</ul>
</div>
<div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
<h1 class="page-header">Create New Item</h1>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<?php $this->load->view('templates/footer_inc'); ?>
</body>
</html>
I've been researching about this issue and I can't seem to find out. This is my first time doing PHP Framework.
I am hoping for your great answers.
Upvotes: 1
Views: 703
Reputation: 1864
you have used inventory/createitem
in your controller where it should be the controller_name/function_name and route array contain your url param
If you want url like this http://yoururl.com/inventory/createitem
then you need to add like following:
$route['createitem'] = "inventory/create_item";
where, createitem is url param (you can change whatever you want) and create_item should be your function name inside inventory controller.
Upvotes: 1
Reputation: 648
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['default_controller'] = "inventory";
$route['404_override'] = '';
$route['create_item'] = "inventory/create_item";
use this in your config as create_item is your function name in inventory controller.
Upvotes: 1
Reputation: 7662
Use
$route['create_item'] = "inventory/create_item";
Instead of
$route['create_item'] = "inventory/createitem";
Because in you collator function name is create_item()
Alternative Solution
Change function create_item()
into function createitem()
Upvotes: 1