【问题标题】:Read works, add, edit, delete do not in Grocery Crud library Codeigniter在 Grocery Crud 库 Codeigniter 中阅读作品、添加、编辑、删除不要
【发布时间】:2014-05-28 06:33:15
【问题描述】:

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

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

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

【问题讨论】:

  • 显示错误页面的快照。

标签: php codeigniter codeigniter-2 grocery-crud


【解决方案1】:

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

你现在可以走了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-11-15
    相关资源
    最近更新 更多