Beginner Problem |
[eluser]gunner0007[/eluser]
Hi guys, I am a complete newbie. I have read the user guide countless times trying to figure this out, searched google enough times as well with no luck so far. I'm new to CodeIgniter and just making a simple blog. Can someone help me out here? Here is what I have so far.. If it doesn't make sense , which it may not I'll just have to do another search but I'm having problems inserting data into my post data into the database. I'm able to pass the post as a variable and echo it to see what it is. However when trying to insert it via command in the model nothing happens. Controller <?php public function update() { $this->load->helper('form'); $data['heading'] = 'Enter Info Here'; $data['title'] = 'Update Blog'; $this->load->model('news_model'); $data['data'] = $this->news_model->insert_blog(); $this->load->view('update_blog',$data); } } ?> Model class News_model extends CI_Model { public $content = ''; public function News_model() { parent::__construct(); public function insert_blog() { $this->load->database(); $this->load->library('input'); $data = $this->input->post('entry'); $this->content = $this->input->post('entry'); $data = array( 'Content' => $this->input->post('entry')); $this->db->insert('blog', $data); } } ?> View <html> <title><?php echo $title?></title> <h2><?php echo $heading?></h2> <?php echo form_open('blog/update'); echo form_textarea('entry','Enter Information Here'); echo '<br />'; echo form_submit('mysubmit', 'Add Post!') ?> </html>
[eluser]marjune[/eluser]
first of all from your view youre going to post it in your controller like this for example $entry = $this->input->post(‘entry’); $data = $this->input->post(‘data’); $this->news_model->insert_blog($entry, $data); and in the model public function insert_blog($entry, $data) { $this->load->database(); //do insert }
[eluser]Sanjay Sarvaiya[/eluser]
use code tags for code samples. as per CI-Structure pass operational data from controller to model your controller code will look like Code: //controller
[eluser]gunner0007[/eluser]
Thanks for the help, will go through this. Does anyone have any other links or good books/tutorials where I can learn CI? [quote author="Sanjay Sarvaiya" date="1341385885"]use code tags for code samples. as per CI-Structure pass operational data from controller to model your controller code will look like Code: //controller [/quote]
[eluser]Sanjay Sarvaiya[/eluser]
You can learn CI from User Guide. http://ellislab.com/codeigniter/user-guide/ good luck. |
Welcome Guest, Not a member yet? Register Sign In |