![]() |
passing variable - shows invalid variable ... - 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: passing variable - shows invalid variable ... (/showthread.php?tid=92563) |
passing variable - shows invalid variable ... - arcmax98 - 03-07-2025 this should have been easy.... but for some reason its not working ... Controller.. Code: <?php Code: <?=$this->extend("layouts/postlogin_layout")?> Quote:ErrorException - Undefined variable $js_to_loadI have tried everything .. Code: $this->load->view('/dashboard',$data); if in the view i put Code: print_r($_SESSION); I know i am making a very small mistake some where just dont know where ... RE: passing variable - shows invalid variable ... - ozornick - 03-07-2025 Are you really getting to the place where the template is output? redirect() does not interrupt execution? If so, do you need to set the default value: echo $js_to_load ?? 'Hello'; RE: passing variable - shows invalid variable ... - Fido L Dido - 03-08-2025 This is bizarre because I think the code looks fine. My best guess is that your dashboard view is getting returned somewhere else where $js_to_load isn't passed to it. Could it be something to do with the redirects, or perhaps another controller method is returning the dashboard view. That's where I'd start to look. Alternatively you have unearthed a CI bug, but I think this seems unlikely. I might try renaming the variable to minimise this as a possibility. RE: passing variable - shows invalid variable ... - demyr - 03-08-2025 Can you try print_r() in your controller? PHP Code: echo "<pre>"; RE: passing variable - shows invalid variable ... - InsiteFX - 03-09-2025 What version of CodeIgniter 4 are you running? Another thing you can try is this: PHP Code: // Views/data.php Did you try passing it like this? PHP Code: $data["js_to_load"] = "hello"; RE: passing variable - shows invalid variable ... - InsiteFX - 04-12-2025 Also I found that in the views with CodeIgniter 4.6.0 and PHP 8.4.5 I have to add the following in my views PHP Code: <?php |