Php 代码点火器:Can';无法获取请求的页面
我对CodeIgniter 2有问题。它返回了一个404错误。这是我的密码: config/routes.phpPhp 代码点火器:Can';无法获取请求的页面,php,codeigniter,Php,Codeigniter,我对CodeIgniter 2有问题。它返回了一个404错误。这是我的密码: config/routes.php <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); $route['default_controller'] = "inventory"; $route['404_override'] = ''; $route['create_item'] = "inventory/creat
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
$route['default_controller'] = "inventory";
$route['404_override'] = '';
$route['create_item'] = "inventory/createitem";
<?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');
}
}
<!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>
创建新项目
我一直在研究这个问题,但似乎没有发现。
这是我第一次做PHP框架
我希望你能给出很好的答案。使用
$route['create_item'] = "inventory/create_item";
而不是
$route['create_item'] = "inventory/createitem";
因为在您的collator函数名是create\u item()
替代解决方案
将
函数create\u item()
更改为函数createitem()
您在控制器中使用了库存/createitem
,它应该是控制器名称/函数名称,并且路由数组包含您的url参数
如果你想要像这样的urlhttp://yoururl.com/inventory/createitem
然后您需要添加以下内容:
$route['createitem'] = "inventory/create_item";
其中,createitem是url参数(您可以随意更改),而create_item应该是库存控制器中的函数名。您试图访问的url是什么?您在config/routes.php中创建了$route['create_item']=“inventory/createitem”;它搜索函数createitem,而函数名为create_item@AaronAlfonso您是否已将config.php文件配置为
$config['index\u page']=''
并且您在主目录中是否有htaccess来进行套件?如果没有,则需要在url中包含index.php。
$route['createitem'] = "inventory/create_item";