CodeIgniter Forums
pass data fom view to inlcuded views and back - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Model-View-Controller (https://forum.codeigniter.com/forumdisplay.php?fid=10)
+--- Thread: pass data fom view to inlcuded views and back (/showthread.php?tid=92188)



pass data fom view to inlcuded views and back - 4usol - 12-19-2024

Hello,

i try to create a kind of templateset,

in my controller i call the mainpage like this
"
$data['view_page']= $page;  //here is the main-content-filename for example "login" (.php)
$data['view_data']= $dataP; //Some data
echo view('templates/v1/create_page', $data);
"

in the "create_page" i include a lot of single files to seperate the different parts like this
"
    $data['data']=$view_data;                  //pass some data from controller to subfiles !?

    $this->include($view_page,$data);  //here i include my main-content-file for example "login"

  //from this mainfile i need access to the $data vars in the following files, but all my tries failed. Is it possible? How?

  $this->include('templates/v1/head',$data);
  $this->include('templates/v1/header',$data);
  $this->include('templates/v1/sidebar_left',$data);

"

main-content-file for example "login"
"
  //The following $data i need in the mainpage AND also included files like head, header etc. (as shown on top)
$data['view_template']=array(  'val1'  =>  'default', 'val2'=>''...);

$this->section('title') ?>Some content here <?= $this->endSection() ?>
"
 
Hope i could explain what i want to do?


RE: pass data fom view to inlcuded views and back - InsiteFX - 12-19-2024

Sessions / Cookies?


RE: pass data fom view to inlcuded views and back - 4usol - 12-20-2024

yes thats always a way, good idear, but, is there no direct way to pass the vars to the file?


RE: pass data fom view to inlcuded views and back - abatrans - 12-21-2024

Instead of using:

PHP Code:
$this->include('templates/v1/head',$data);
$this->include('templates/v1/header',$data);
$this->include('templates/v1/sidebar_left',$data); 


I suggest you use:

PHP Code:
echo view'templates/v1/head',$data);
echo 
view('templates/v1/header',$data);
echo 
view('templates/v1/sidebar_left',$data);