Welcome Guest, Not a member yet? Register   Sign In
Weird error
#1

[eluser]Joaquin Encinas[/eluser]
Hello Im new to code Igniter I doing the blog in 20 min tutorial and Im getting this error



A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at /home/jencinas/public_html/CodeIgniter/system/application/controllers/blog.php:51)

Filename: helpers/url_helper.php

Line Number: 541


here is the code

<?php

class Blog extends Controller {



function Blog()
{

parent::Controller();

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


}


function index()
{

$data['title'] = "My Blog Title";
$data['heading'] = "My Blog Heading";
$data['query'] = $this->db->get('entries');

$this->load->view('blog_view', $data);

}

function comments()
{
$data['title'] = "My Comment Title";
$data['heading'] = "My Comment Heading";
$this->db->where('entry_id', $this->uri->segment(3));
$data['query'] = $this->db->get('comments');
$this->load->view('comment_view', $data);
}


function comment_insert()
{

$this->db->insert('comments', $_POST);

redirect('blog/comments/'.$_POST['entry_id']);
}

}

?>


it is posting the comments but not redirecting to the http://www.encinashosting.com/CodeIgnite...comments/1 like is suppose to



any suggestions how to fix this

???

Thank you
#2

[eluser]Cristian Gilè[/eluser]
Remove the ?> closing tag from your code and remove any space before the <?php opening tag.

Code:
<?php

class Blog extends Controller {



function Blog()
  {
    
        parent::Controller();
      
        $this->load->helper(‘url’);
        $this->load->helper(‘form’);
    

  }


  function index()
  {
    
      $data[‘title’] = “My Blog Title”;
      $data[‘heading’] = “My Blog Heading”;
      $data[‘query’] = $this->db->get(‘entries’);
    
      $this->load->view(‘blog_view’, $data);

  }
    
      function comments()
      {
      $data[‘title’] = “My Comment Title”;
      $data[‘heading’] = “My Comment Heading”;
      $this->db->where(‘entry_id’, $this->uri->segment(3));
      $data[‘query’] = $this->db->get(‘comments’);
      $this->load->view(‘comment_view’, $data);
      }
    
    
    function comment_insert()
      {
    
      $this->db->insert(‘comments’, $_POST);
      
        redirect(‘blog/comments/’.$_POST[‘entry_id’]);
      }

}


Cristian Gilè
#3

[eluser]Joaquin Encinas[/eluser]
Thank you Cristian, why the ?> closing tag is not needed?
#4

[eluser]Cristian Gilè[/eluser]
http://ellislab.com/codeigniter/user-gui...losing_tag


Cristian Gilè
#5

[eluser]Joaquin Encinas[/eluser]
Thank you I am liking Code igniter a lot so far




Theme © iAndrew 2016 - Forum software by © MyBB