0

I ham writing the follow Codeigniter code, but I keep getting a 404 error. Any thoughts?

funding_controller.php

class Funding extends CI_Controller {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();

    }


    public function index()
    {

        $this->load->model('funding_model');

        $data['funds'] = $this->funding_model->getAll();
        $this->load->view('funding_list', $data);
    }
}

funding_model.php

  class Funding extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }

    function getAll() {

        $query = $this->db->get('funds');

        return $query->result();

    }


}    

funding_list.php

foreach($funds as $row) {

   echo $row->opportunity_name;
   echo "<br />";

}

The default route points to funding_controller. Thoughts?

2 Answers 2

4
  1. controller name and class name should be same and file name in lower case

    funding.php

    And try following url

    http://domain.com/funding/index

  2. Model class name different from controller name like funding_model or anything else and no need to suffix _model in ->load->model()

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks, I've done as you suggested but I'm now getting: Fatal error: Cannot redeclare class funding in /webusers/ad6vcf/public_html/funding-list/application/models/funding.php
model file name and class different from controller for example funding_model
Please bear in mind that filenames and Classes of controllers must start with capital letter.Some (or all) server throws an error when calling controllers starting on lower case lettter. Read codeigniter.com/user_guide/general/…
0

Use first letter in capital for controller n model file name.

For example:

 Founding_controller.php
 Founding_model.php

And class name should be filename (as it is).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.