添加编辑视图删除给出的页面没有找到404杂货CRUD


add edit view remove gives page not found 404 on grocery CRUD

我是新来的groceryCRUD和我试图显示一个简单的表与所有功能,实现不是在索引方法中推荐的教程。

我正在使用一个wamp

基本url:

$config['base_url'] = 'localhost/main_folder/';

控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Welcome extends CI_Controller {
public function index()
{
        $this->load->helper('url');
$this->load->view('home');
}
    public function categorie()
{
        $this->load->helper('url');
$this->load->library('grocery_CRUD');
        $crud = new grocery_CRUD();
        $crud->set_table('categorie');
        $crud->set_subject('Categoria');
        $crud->fields('nome','descrizione','note');
        $output = $crud->render();
        $this->load->view('categorie',$output);
}
}

由于我使用的CSS主题,视图很长,所以我将包括相关的(我认为)部分:

<?php foreach($css_files as $file): ?>
    <link type="text/css" rel="stylesheet" href="http://<?php echo $file; ?>" />
<?php endforeach; ?>
<?php foreach($js_files as $file): ?>
    <script src="http://<?php echo $file; ?>"></script>
<?php endforeach; ?>
<?php echo $output; ?>

当我点击添加编辑和查看,我得到一个404错误从编码器与url,我可以看到不太好:

http://localhost/main_folder/index.php/localhost/main_folder/index.php/categorie/add

我试图把基础url放回:

$config['base_url'] = '';

但是url出现的很奇怪:

http://[::1]/main_folder/index.php/categorie/add

我也试着把http://:

$config['base_url'] = 'http://localhost/pannello_preventivi/';

像这样,我设法有一个干净的url:

http://localhost/main_folder/index.php/categorie/add

但是仍然得到404错误,有人可以帮助我吗?

我发现codeigniter需要一个路由为每个动作调用,所以足以修改codeigniter配置文件夹中的routes.php并添加每个路由,我这样做:

$route['default_controller'] = 'welcome';
$route['categorie'] = 'welcome/categorie';
$route['categorie/add'] = 'welcome/categorie/add';
$route['categorie/insert'] = 'welcome/categorie/insert';
$route['categorie/insert_validation'] = 'welcome/categorie/insert_validation';
$route['categorie/success/:num'] = 'welcome/categorie/success';
$route['categorie/delete/:num'] = 'welcome/categorie/delete';
$route['categorie/edit/:num'] = 'welcome/categorie/edit';
$route['categorie/update_validation/:num'] = 'welcome/categorie/update_validation';
$route['categorie/update/:num'] = 'welcome/categorie/update';
$route['categorie/ajax_list_info'] = 'welcome/categorie/ajax_list_info';
$route['categorie/ajax_list'] = 'welcome/categorie/ajax_list';

在那一页上,一切都像魔法一样有效。如果你想要一个适用于同一控制器的参数解:

$route['(:any)/add'] = 'welcome/$1/add';
$route['(:any)/insert'] = 'welcome/$1/insert';
$route['(:any)/insert_validation'] = 'welcome/$1/insert_validation';
$route['(:any)/success/:num'] = 'welcome/$1/success';
$route['(:any)/delete/:num'] = 'welcome/$1/delete';
$route['(:any)/edit/:num'] = 'welcome/$1/edit';
$route['(:any)/update_validation/:num'] = 'welcome/$1/update_validation';
$route['(:any)/update/:num'] = 'welcome/$1/update';
$route['(:any)/ajax_list_info'] = 'welcome/$1/ajax_list_info';
$route['(:any)/ajax_list'] = 'welcome/$1/ajax_list';
$route['(:any)/read/:num'] = 'welcome/$1/read';
$route['(:any)/export'] = 'welcome/$1/export';

我通过在config.php上正确设置base_url来解决这个问题:

$config['base_url'] = 'http://yourdomain/appname/';

…希望对大家有所帮助。