我是关于groceryCRUD的新手,我正在尝试显示一个包含所有功能的简单表,实现不在教程中重新编写的索引方法中。
我正在使用一个wamp
基本网址:
$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; ?>
当我点击添加编辑和查看时,我从codeigniter获得404错误,我看到的网址不好:
http://localhost/main_folder/index.php/localhost/main_folder/index.php/categorie/add
我试图将基本网址恢复为:
$config['base_url'] = '';
但网址很奇怪:
http://[::1]/main_folder/index.php/categorie/add
我也试着把http://:
$config['base_url'] = 'http://localhost/pannello_preventivi/';
像这样,我设法有一个干净的网址:
http://localhost/main_folder/index.php/categorie/add
但仍有404错误,有人可以帮我吗?
答案 0 :(得分:0)
我发现codeigniter需要一个调用avery动作的路由,所以是enaugh修改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';
答案 1 :(得分:0)
我通过在base_url
上正确设置config.php
解决了该问题:
$config['base_url'] = 'http://yourdomain/appname/';
...希望这对其他人有帮助。