passing variable - shows invalid variable ... |
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 ...
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';
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.
Can you try print_r() in your controller?
PHP Code: echo "<pre>";
03-09-2025, 02:09 AM
(This post was last modified: 03-09-2025, 09:33 PM by InsiteFX. Edit Reason: Updated content )
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"; What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
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 What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
|
Welcome Guest, Not a member yet? Register Sign In |