Welcome Guest, Not a member yet? Register   Sign In
problem with my template
#1

[eluser]raffie77[/eluser]
Hi people, i'm a newbe here :-)

I have created a template.

this is my conroler:

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Fuel extends CI_Controller {

       public function __construct()
       {
       parent::__construct();
            $this->load->helper('html');
            $this->load->library('table');
       }
      
    public function index()  {
        $this->welkom();
    }
    
    public function welcome(){
        $data['title'] = 'welcome';
        $data['main_content'] = 'welcome';
        $this->load->view("template", $data);
    }
    
    public function image() {
    $data['title'] = 'test';
    $data['main_content'] = 'imagetest';
    $this->load->view("template", $data);
    }
    
    public function overview() {
        $data['title'] = 'overview';
        $this->load->model('get_DB');
        $data['main_content'] = $this->get_DB->overview() ;
        $this->load->view("template", $data);
    }
}

this is my model:

Code:
<?php

class Get_DB extends CI_Model
{
  
    public function overview() {
        $query = $this->db->query("SELECT * FROM invoer "
        . "ORDER BY dateDESC");
        $tmpl = array ( 'table_open'  => '<table border="1" cellpadding="2" cellspacing="1">' );
        $this->table->set_template($tmpl);
        echo $this->table->generate($query);
    }
}

under views I have this header:

Code:
<!DOCTYPE html>
&lt;html&gt;
&lt;head&gt;
    &lt;meta charset="utf-8" /&gt;
    &lt;?php echo link_tag('css/fuel.css'); ?&gt;
&lt;title&gt;&lt;?php echo $title ?&gt;&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
    <hr>
    <h2>&lt;?php echo ucfirst($title) ?&gt;</h2>
    <hr>

and I have a footer with som basic stuff.
oh yes and my template file under views:

Code:
&lt;?php

$this->load->view('templates/header');
$this->load->view($main_content);
$this->load->view('templates/footer');

well the problem is this:
when I open index, welcome, and image, all goes well

but when I open overview, I get an error:

Quote:A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\test\application\models\get_DB.php:16)

Filename: core/Common.php

Line Number: 442

An Error Was Encountered

Unable to load the requested file: .php

btw C:\xampp\htdocs\test\application\models\get_DB.php:16 =
Code:
echo $this->table->generate($query);

anny idea what goes wrong?

Ralph
#2

[eluser]CroNiX[/eluser]
Because you are echoing straight from a controller or model instead of using the output class or view, so that gets output immediately followed by the headers and CI's output, which causes the error because you output something before headers were sent, and then you sent more headers.
#3

[eluser]raffie77[/eluser]
[quote author="CroNiX" date="1382468142"]Because you are echoing straight from a controller or model instead of using the output class or view, so that gets output immediately followed by the headers and CI's output, which causes the error because you output something before headers were sent, and then you sent more headers.[/quote]

Ok so do I understand it correctly dat you don't use echo or print(f) in a contorler or model?
instead of that I use return, all the echo's are placed in the view?
#4

[eluser]Otemu[/eluser]
Hi,

No you shouldn't be echoing/print anything in model/controllers. The only time I might echo/print/dump something in the controller/model is when am testing something and want to see what is returned.

The view is the presentation layer, so anything you need to echo out should be in that view.





Theme © iAndrew 2016 - Forum software by © MyBB