variable to layout |
hi how can i send variable to footer in layout ( with <?= $this->renderSection('content') ?> ) ? variable set to every view that extend a template : <?= $this->extend('templates/layout_user') ?>
You can set the variable from your controller, and then show the variable through a footer include:
app/Controllers/Cart.php PHP Code: <?php PHP Code: <?= $this->renderSection('content') ?> app/Views/cart/index.php PHP Code: <?= $this->extend('App\Views\templates\layout_user') ?> app/Views/templates/footer.php PHP Code: <p><?= $variable; ?></p> Display: Code: <p>Some cart content here</p>
The footer is used from several page of my project , i cannot set variable in every method of every controller that show the template . I need a global variable (data from db ) to set user contact (email , telephone ecc.) in footer . It's possible to do ?
(01-19-2022, 08:56 AM)pippuccio76 Wrote: The footer is used from several page of my project , i cannot set variable in every method of every controller that show the template . I need a global variable (data from db ) to set user contact (email , telephone ecc.) in footer . It's possible to do ? I like to set in my base controller PHP Code: $this->data['variable'] = "variable info"; And then in each of my app controllers I just call the whole thing PHP Code: echo view('Cart/index', $this->data);
I am facing the similar issue, and unfortunately there is no documentation regarding the issue (should be in view-layout related section in the documentation) which I presume there is no feature about it in the current version of CI. I ended up utilizing the layout as simple as possible with very little needs of logic, and utilizing other view's features, like loading multiple views, cell, etc. Flexible, but less structured. Lets hope CI team adds the feature in the future.
------------ EDIT: I think made a mistake by assuming that there is no feature about it because there is no documentation about it. It seems we don't need to pass any data to the layout since it can detect all data passed from controller to view. |
Welcome Guest, Not a member yet? Register Sign In |