Gil Gil - 2 months ago 19
PHP Question

Nested views | Codeigniter 3

I need to neste a view that's already nested...

i mean, i have the view

app
inside this i have 5 nested views, but i need inside one of these 5 views, anoter nested view

its something like

--> App
----> view 1
----> view 2
----> view 3
----> view 4
----> view 5
------> view 5.1
------> view 5.2
------> view 5.3
------> view 5.4



Controller


// includes
$data['footer'] = $this->load->view('includes/footer', NULL, TRUE);

// App
$data['menuProfile'] = $this->load->view('app/menuProfile', NULL, TRUE);
$data['sidebarMenu'] = $this->load->view('app/sidebarMenu', NULL, TRUE);
$data['topNavigation'] = $this->load->view('app/topNavigation', NULL, TRUE);
$data['menuFooter'] = $this->load->view('app/menuFooter', NULL, TRUE);

// Dashboard
$data['dashboard'] = $this->load->view('app/dashboard/dashboard', $data, TRUE);
$dataDashboard['dinp'] = $this->load->view('app/dashboard/dinp', NULL, TRUE);
$dataDashboard['dispTitle'] = $this->load->view('app/dashboard/dispTitle', NULL, TRUE);
$dataDashboard['percent'] = $this->load->view('app/dashboard/percent', NULL, TRUE);
$dataDashboard['temp'] = $this->load->view('app/dashboard/temp', NULL, TRUE);
$dataDashboard['velocity'] = $this->load->view('app/dashboard/velocity', NULL, TRUE);


$this->load->view('includes/head');
$this->load->view('app', $data);
$this->load->view('includes/jquery');


i tried this way but i got this error

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: percent

Filename: dashboard/dashboard.php

Line Number: 10

Backtrace:

File: C:\xampp\htdocs\m2m\application\views\app\dashboard\dashboard.php Line: 10 Function: _error_handler

File: C:\xampp\htdocs\m2m\application\controllers\app.php Line: 34 Function: view

File: C:\xampp\htdocs\m2m\index.php Line: 315 Function: require_once


what im doing wrong? (noob at codeigniter)

Edit


App | View


<body class="nav-md">
<div class="container body">
<div class="main_container">
<div class="col-md-3 left_col menu_fixed">
<div class="left_col scroll-view">
<div class="navbar nav_title" style={{border: '0'}}>
<a href="index.html" class="site_title"><i class="fa fa-home"></i> <span>M2MWare!</span></a>
</div>

<div class="clearfix"></div>
<?=$menuProfile?>
<br />
<?=$sidebarMenu?>
<?=$menuFooter?>
</div>
</div>
<?=$topNavigation?>
<!-- PageContent -->
<?=$dashboard?>
<?=$footer?>
</div>
</div>

</body>
</html>



Dashboard | View


<div class="right_col" role="main" id="Dashboard">
<div class="">
<div class="clearfix"></div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_content">
<div class="col-md-3 col-xs-12 widget widget_tally_box">
<!-- percent -->
<?=$porcentaje?>
<!-- dinp -->
<?=$dinp?>
<!-- dinp -->
<?=$dinp?>
<!-- temp -->
<?=$temp?>
</div>
</div>
</div>
</div>
</div>
</div>


Here's an img how display the error in the browser

enter image description here

i need write something, because SO... just ignore this part

Answer

If dashboard.php contains the code you show under

Blockquote

and it is loaded with this line

$data['dashboard'] = $this->load->view('app/dashboard/dashboard', $data, TRUE);

then the problem is that you do not pass your secondary views to dashboard.php.

I believe all you need to do is reorder one line of code and pass the appropriate data to the "dashboard" view. Try this.

// Dashboard
$dataDashboard['dinp'] = $this->load->view('app/dashboard/dinp', NULL, TRUE);
$dataDashboard['dispTitle'] = $this->load->view('app/dashboard/dispTitle', NULL, TRUE);
$dataDashboard['percent'] = $this->load->view('app/dashboard/percent', NULL, TRUE);
$dataDashboard['temp'] = $this->load->view('app/dashboard/temp', NULL, TRUE);
$dataDashboard['velocity'] = $this->load->view('app/dashboard/velocity', NULL, TRUE);
$data['dashboard'] = $this->load->view('app/dashboard/dashboard', $dataDashboard, TRUE);