Question

I have the following code in my controller.

$this->view_data['page_content'] = 'login';
$this->load->view('main',$this->view_data);
if ($bool == TRUE){
    $this->view_data['page_content'] = 'dash';
    $this->load->view('main',$this->view_data);
}

Upon login, I would like to replace the content in login.php with the content in dash.php. However, the code in the if loop is appended at the bottom of the first one.

Result:

<html lang="en">
<head>
</head>
<body>
<h1>header</h1> //header and footer is in main.php

//login form in login.php
<form method="post"></form>

<h1>footer</h1>
</body>
</html>

<html lang="en">
<head>
</head>
<body>
<h1>header</h1>

<div id="container">
//contents in dash.php
</div>

<h1>footer</h1>
</body>
</html>
Was it helpful?

Solution

$this->view_data['page_content'] = 'login';    
if ($bool === TRUE){
    $this->view_data['page_content'] = 'dash';
}
$this->load->view('main',$this->view_data);

In your view add

<?php $this->load->view($page_content); ?> 

Where you want the view loaded

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top