Welcome Guest, Not a member yet? Register   Sign In
Content displayed in wrong order
#1

[eluser]Unknown[/eluser]
Newbie here... I suspect this may be an issue others have previously encountered but I haven't found it up this point so here I go...

I'm still at the start of my journey creating my portal, and at this point I'm just trying to output some content from my session array value. So far this is what I have:

models/auth_user.php:
Code:
class Auth_user extends CI_Model {
    function __construct() {
      parent::__construct();
    }

    function get_user() {
      if (isset($_SERVER["HTTP_IV_USER"])) {
        return $_SERVER["HTTP_IV_USER"];
      }
      else {
        return -1;
      }
    }

    function set_session($userid) {
      $this->session->set_userdata("userid", $userid);
      echo $this->session->userdata("userid");
    }
  }

I have an "echo" call in set_session() to make sure I'm actually executing that function.

views/header.php
Code:
<html>
  <head>
    <title>GTS Drawings Portal :: <?=$mode?></title>
  </head>
  <body>

    <table>
      <thead>
        <th>GTS Drawings Portal :: &lt;?=$mode?&gt;</th>
      </thead>
      <tr>
        <td>
        &lt;!-- end header --&gt;

views/footer.php
Code:
&lt;!-- start footer --&gt;
        </td>
      </tr>
    </table>

  &lt;/body&gt;
&lt;/html&gt;

controllers/main.php:
Code:
class Main extends CI_Controller{
    public function index() {
      $this->load->library('session');
      $this->load->model("Auth_user");

      $data["mode"] = "Main";
      $this->load->view('header',$data);

      $userid = $this->Auth_user->get_user();
      if (isset($userid)) {
        $this->Auth_user->set_session($userid);
      }
      $this->load->view('footer');
    }
  }

When the content is generated the echo I put in the method above is first to appear:
Code:
oprdnec&lt;html&gt;
  &lt;head&gt;
    &lt;title&gt;GTS Drawings Portal :: Main&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;

    <table>
      <thead>
        <th>GTS Drawings Portal :: Main</th>

      </thead>
      <tr>
        <td>
        &lt;!-- end header --&gt;
        &lt;!-- start footer --&gt;
        </td>
      </tr>
    </table>

  &lt;/body&gt;
&lt;/html&gt;
I'm trying to get it to appear between the two HTML comment lines.

Like I said I suspect this is something simple; I'd greatly appreciate any useful assistance.

- Joe
#2

[eluser]pbflash[/eluser]
You can't echo something in your controller/model and have it appear between 2 views. PHP code is executed before the output so it will always appear on top of the page. You need to return what you want from the model to the controller and then pass the information into a view like you are doing with the mode in the header view.
#3

[eluser]CroNiX[/eluser]
All CI output is buffered, and as pbflash mentioned, anything echo'd out of a controller bypasses that and gets sent to the browser immediately, followed by the contents of the buffer.
#4

[eluser]Aken[/eluser]
Code:
$this->load->view('header');

$this->output->append_output('content');

$this->load->view('footer');




Theme © iAndrew 2016 - Forum software by © MyBB