Reputation: 141
I've just started to learn CodeIgniter and gotten trouble with example below: My Controller:
class Site extends CI_Controller { public function __construct() {My Model is:
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(); } }
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!!
Upvotes: 1
Views: 5691
Reputation: 2522
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.
Upvotes: 1
Reputation: 704
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..
Upvotes: 3