include with variable (solved) |
Hello,
I would like to know how to pass a variable in an include. Indeed when I do the classic way codeigniter returns me an error. PHP Code: <?php if (!empty($galeries) && is_array($galeries)) : thank you in advance for any help!
When a file is included, the code it contains inherits the variable scope of the line on which the include occurs.
Any variables available at that line in the calling file will be available within the called file, from that point forward. However, all functions and classes defined in the included file have the global scope. What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Thank you for your reply.
However i am not sure i understood correctly. I still have the same error ==> see attached file It's like the foreach loop variable doesn't exist in the include. Anyway i got around the problem by putting the foreach in the include, it works but not exactly what i wanted attachements : https://ibb.co/mFMGMVX
Use view instead of include.
Like echo view('includes/include_card',$galerie) (02-12-2021, 08:37 PM)waleed Wrote: Use view instead of include. Hi, Sorry but don't work (same error) (02-13-2021, 12:03 AM)nfaiz Wrote: Use View Cell?I don't want to use controller (02-13-2021, 11:18 AM)ikesela Wrote: pass thru controller ( then return thru view -> load include using view)It's the same thing, unless I didn't understand correctly If there are others ideas...
This should work. Change your include part to this one.
PHP Code: <?= $this->setData(compact('galerie'))->include('includes/include_card') ?> |
Welcome Guest, Not a member yet? Register Sign In |