CodeIgniter Forums
Passing data from controller to menu - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Passing data from controller to menu (/showthread.php?tid=77285)



Passing data from controller to menu - pippuccio76 - 08-11-2020

hisorry for english , if i want pass data from controller to menu can i use this :

PHP Code:
<?= $this->include('templates/head'?>
<body>
    <?= $this->include('templates/menu'?>
    <div class="container py-3">
        <?= $this->renderSection('content'?>
    </div>
<?= $this->include('templates/footer'?>

Or must  i echo the view in controller ?like this:

 
PHP Code:
echo view('templates/header_client',$data );
echo view('templates/menu_client',$data );

echo view('myViewFolder/myView',$data );

echo 
view('templates/footer_client',$data ); 



RE: Passing data from controller to menu - demyr - 08-12-2020

The second one looks much better. But just send only one $data. You can do it on header. If this header is for all pages, then you will not have any problem.


PHP Code:
echo view('templates/header_client',$data );
echo 
view('templates/menu_client');
echo 
view('myViewFolder/myView');
echo 
view('templates/footer_client'); 



RE: Passing data from controller to menu - InsiteFX - 08-12-2020

What I do for the data is create a dummy view file that is empty called view_data.php

PHP Code:
$data = [
    'pageDescription' => '',
    'pageKewords'     => '',
    'pageAuthor'      => '',
    'pageTitle'       => '',
];

echo 
view('view_data'$data);
echo 
view('layouts/index-1'); 

Then all I have to do is load the view_data first and all views get the data.