我已经完成了示例并安装了所有内容。
表的读取或显示方法可以正常工作,但每当我尝试添加,删除或编辑注册表时,都会出现一个窗口并说:
404 Page Not Found
The page you requested was not found.
这是我的控制器
class Welcome extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('grocery_CRUD_model');
$this->load->database();
$this->load->helper('url');
$this->load->library('grocery_CRUD');
}
public function index()
{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('students');
$crud->set_relation('class','class','class');
$crud->display_as('name','Name of Student');
$crud->set_subject('Students');
$crud->columns('name','class','roll_no');
$crud->add_fields('name','class','roll_no');
$crud->required_fields('name','class','roll_no');
$crud->unset_export();
$crud->unset_print();
$output = $crud->render();
$this->load->view('home', $output);
}
}
当我点击添加按钮URL变为
http://localhost/index.php/add
错过了什么? 我是codeigniter和Grocery Crud的新手......
答案 0 :(得分:3)
在Welcome
控制器中创建另一个函数,将所有代码从index()
函数移动到新函数,如:
public function myFunction()
{
$crud = new grocery_CRUD();
$crud->set_theme('datatables');
$crud->set_table('students');
$crud->set_relation('class','class','class');
$crud->display_as('name','Name of Student');
$crud->set_subject('Students');
$crud->columns('name','class','roll_no');
$crud->add_fields('name','class','roll_no');
$crud->required_fields('name','class','roll_no');
$crud->unset_export();
$crud->unset_print();
$output = $crud->render();
$this->load->view('home', $output);
}
并将index()
函数重定向到此方法:
public function index()
{
redirect("welcome/myFunction");
}
访问您的杂货店页面
http://localhost/index.php/welcome/newFunction
或者只是
http://localhost/index.php/welcome
你现在好了。