读取工作,添加,编辑,删除不要在Grocery Crud库Codeigniter中

时间:2014-04-14 10:25:13

标签: php codeigniter codeigniter-2 grocery-crud

我已经完成了示例并安装了所有内容。

表的读取或显示方法可以正常工作,但每当我尝试添加,删除或编辑注册表时,都会出现一个窗口并说:

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的新手......

1 个答案:

答案 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

你现在好了。