CodeIgniter Forums

Full Version: Beginner Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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>&lt;?php echo $heading?&gt;</h2>

&lt;?php
echo form_open('blog/update');

echo form_textarea('entry','Enter Information Here');
echo '<br />';

echo form_submit('mysubmit', 'Add Post!')
?&gt;

&lt;/html&gt;

El Forum

[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

}

El Forum

[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
public function update() {
      $this->load->helper(‘form’);

      $data[‘heading’] = ‘Enter Info Here’;
      $data[‘title’] = ‘Update Blog’;
    
    
      $this->load->model(‘news_model’);
      $data['blog'] = array('content', $this->input->post('entry'));//
      $data[‘data’] = $this->news_model->insert_blog($data['blog']);//
    
      $this->load->view(‘update_blog’,$data);
    
  }
//model insert method you have to do just no need to load any library.
public function insert_blog() {    
    $this->db->insert(‘blog’, $data);
    echo $this->db->last_query();die();//your insert query.
  }




El Forum

[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
public function update() {
      $this->load->helper(‘form’);

      $data[‘heading’] = ‘Enter Info Here’;
      $data[‘title’] = ‘Update Blog’;
    
    
      $this->load->model(‘news_model’);
      $data['blog'] = array('content', $this->input->post('entry'));//
      $data[‘data’] = $this->news_model->insert_blog($data['blog']);//
    
      $this->load->view(‘update_blog’,$data);
    
  }
//model insert method you have to do just no need to load any library.
public function insert_blog() {    
    $this->db->insert(‘blog’, $data);
    echo $this->db->last_query();die();//your insert query.
  }




[/quote]

El Forum

[eluser]Sanjay Sarvaiya[/eluser]
You can learn CI from User Guide.
http://ellislab.com/codeigniter/user-guide/

good luck.