error in defining a subview in codeigniter

322 Views Asked by At

this is my controller

public function index() {
    $this->data['users'] = $this->user_login_model->get();
    $this->data['abc'] = 'admin/user/index';
    $this->load->view ( 'admin/_layout_main', $this->data);
}

this is my view

<div class="container">
    <div class="row">
        <!-- main column -->
        <div class="col-sm-9">

        <?php $this->load->view($abc);?>
        </div>
</div>
</div>

this is the error

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: abc

Filename: admin/_layout_main.php

Line Number: 31 An Error Was Encountered

Unable to load the requested file: .php

1

There are 1 best solutions below

0
On

You can try following:

$data['users'] = $this->user_login_model->get();
$data['content'] = $this->load->view('admin/user/index', $data, true);
$this->load->view('admin/_layout_main', $data);

By this way you can use your view and template in controller function.