Question

I have done the example and installed everything.

The read or display method of table works correctly, but whenever I try to add, delete or edit a registry a windows appears and say:

404 Page Not Found

The page you requested was not found.

Here is my Controller

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);

    }

}

when i click ADD button URL becomes

http://localhost/index.php/add

what is missed? i am new in codeigniter and Grocery Crud...

Was it helpful?

Solution

Create another function in Welcome controller and move all of the code from index() function to new function just like:

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);

    }

And redirect your index() function to this method:

public function index()
    {   
        redirect("welcome/myFunction");
    }

Access your grocery crud page at

http://localhost/index.php/welcome/newFunction

Or simply

http://localhost/index.php/welcome

You're good to go now.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top