session in view file |
(10-12-2019, 08:03 AM)Digital_Wolf Wrote:(10-12-2019, 01:32 AM)jbloch Wrote: How to get session value in view file In CI4?Something like this: Hello, You have 2 possibilities, it depends upon the number of variables of your session you want to transfer. 1. In the view code directly The context ($this) is an instance of the View class --> you don't have access to the Session instance directly. You have to write a bit of code in the View: PHP Code: $session = \Config\Services::session(); 2. Controller code + view code You can also pass the data during the call of the view() method in the Controller. PHP Code: <?php Then, in the view: PHP Code: <?= $item ?> Should work ![]() -- I prefer method 2, it is more about separating Controller and View from a purpose point of view. Regards, |
Messages In This Thread |
session in view file - by jbloch - 10-12-2019, 01:32 AM
RE: session in view file - by Digital_Wolf - 10-12-2019, 08:03 AM
RE: session in view file - by Ekley - 10-13-2019, 02:58 AM
RE: session in view file - by InsiteFX - 10-13-2019, 08:07 AM
|