1

I've just started to learn CodeIgniter and gotten trouble with example below: My Controller:

 class Site extends CI_Controller { public function __construct() {
parent::__construct(); } function index() { $this->load->view('options_view'); } function create() { $data = array ( 'title' => $this->load->input->post('title'), 'content' => $this->load->input->post('content') ); $this->site_model->add_record($data); $this->index(); } }
My Model is:
 class Site_model extends CI_Model { function get_records() { $q = $this->db->get('articles'); return $q->result(); } function add_record($data) { $this->db->insert('articles',$data); return; } } 

My view is:

<pre> <?php echo form_open('site/create');?> <p> <label for="title">Title:</label> <input type="text" name="title" id="title"/> </p> <p> <label for="content">Content:</label> <input type="text" name="content" id="content"/> </p> <p> <input type="submit" value="Submit"/> </p> <?php echo form_close();?> </pre> 

So when I click Submit button I get the error like: Severity: Notice Message: Undefined property: CI_Loader::$input Filename: controllers/site.php Line Number: 19

Any ideas will be usefull!Thanx!!

2 Answers 2

3

try this in your contorller.

 class Site extends CI_Controller { public function __construct() { parent::__construct(); } function index() { $this->load->view('options_view'); } function create() { $data = array ( 'title' => $this->input->post('title'), 'content' => $this->input->post('content') ); $this->site_model->add_record($data); $this->index(); } } 

no need of using load in front of the input statement in the function create. Try it..

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

1 Comment

no mention, if you think it's the answer,then you can accept the enswer. :D
1

The lines should be like

'title' => $this->input->post('title'), 'content' => $this->input->post('content') 

not

'title' => $this->load->input->post('title'), 'content' => $this->load->input->post('content') 

and also you need to load the form helper.so after parent::__construct(); add this line or you can add in your autoload.php page

$this->load->helper('form'); 

Please let me know if you face any problem.

1 Comment

OK! Thanx, I'm using $autoload['helper']

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.