user2576961
user2576961

Reputation: 415

Undefined index body

I'm trying to figure out why when I load this controller it says undefined index body when I am establishing the body with the build method of the library. I'm use phil sturgeon's 1.9 version of his template library.

<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');

class Control_panel extends Backend_Controller
{
public function __construct()
{
    parent::__construct();
}

public function index()
{

    $this->template
        ->title('Control Panel')
        ->set_layout('control_panel_view')
        ->set_partial('sidebar', 'partials/sidebar')
        ->build('dashboard_view');
    //echo '<pre>';
    //var_dump($this->template);
    //echo '</pre>';
    //die();
}
}

This is the same layout minus the sidebar that I use for my login view. And it loads fine.

<!DOCTYPE HTML>
<!--[if lt IE 7]> <html class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>    <html class="lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>    <html class="lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html> <!--<![endif]-->

<head>
<title><?php echo $template['title']; ?></title>

<?php echo $template['partials']['header']; ?>

</head>

<body>

<!-- Start Content -->
<div class="container-fluid login">

    <div id="wrapper">

        <?php echo $template['partials']['sidebar']; ?>

        <?php echo $template['body']; ?>

    </div>

</div>

<?php echo $template['partials']['footer']; ?>

</body>

 </html>

EDIT :

I am still having issues with this and can't seem to get this fixed. Any ideas.

Upvotes: 1

Views: 590

Answers (1)

castis
castis

Reputation: 8223

The error you're getting isnt from any of the code you posted. But it should have come with a filename and line number.

Look for something like $something['body'] somewhere. That array index isn't set but you're trying to use it anyways.

You're not setting $template['body']. Use the template object in the php to do so. Do this

$this->template
    ->title('Control Panel')
    ->set_layout('control_panel_view')
    ->set_partial('sidebar', 'partials/sidebar')
    ->set('body', 'body content!')
    ->build('dashboard_view');

obviously you'll want to change 'body content' to what your content will ultimately be.

Upvotes: 1

Related Questions