Reputation: 209
I have two controllers, two views and a masterpage:
dashboard controller:
class Dashboard extends CI_Controller {
public function index()
{
if($this->session->userdata('login') == true){
$data['title'] = 'Dashboard';
$data['content'] = 'pages/dashboard';
$this->load->view('layout/master', $data);
}
else{
redirect('auth');
}
}
customers controller:
class Customers extends CI_Controller {
public function index()
{
$data['content'] = 'pages/add_customer';
$this->load->view('layout/master', $data);
}
public function add(){
$data['content'] = 'pages/add_customer';
$this->load->view('layout/master', $data);
}
}
And my master page:
<head>
<meta charset="utf-8" />
<title><?php echo isset($title)? $title: NULL; ?></title>
<?php $this->load->view('layout/header'); ?>
</head>
<body>
<!-- BEGIN PAGE BASE CONTENT -->
<?php $this->load->view($content);?>
<!-- END PAGE BASE CONTENT -->
</body>
The problem is When i call dashboard, the view runs in the template and everything is fine. When i call customers, again everything runs fine and the template is OK. But when i call the add method from customers controller, It's like the master page doesn't work and the template messed up. Like there is no CSS or something. What's the problem? Thanks in advance :)
Upvotes: 1
Views: 666
Reputation: 502
I personally do not rely on native CI functionality for any template/view stuff. I use Stencil, which isn't actively developed anymore, but it worked on 2 and works on 3. I modified the core library file to handle session and config variables, but this thing is beautiful. It's at the center of every one of my CI deployments.
Stencil on scotch.io via Github
This absolutely doesn't answer your question and certainly deserves to be down-voted or flagged for that reason. But CI view handling is awkward, so I never endorse using it. I don't know why Stencil isn't built in.
Upvotes: 1