![]() |
Hi everyone!
I like using Cells in my project, especially the controlled ones. And I'd rather to use typed variables in my project. But when i try to use typed peroperties in controlled cells, I get Code: Undefined variable $typedVariable Here is my code (I created a small project just for testing this) Code: JustATestCell.php PHP Code: <?php Code: just_a_test.php PHP Code: <div> Code: main view file PHP Code: ... So my question is: what am I doing wrong? Am I supposed not to use typed properties in cells? Thanks in advance
View Cells must return a string not an int.
What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
(05-29-2024, 04:00 AM)Bosborne Wrote: How are you passing the variable to the view? As you can read here, those are made available automatically to the view file, because I'm using controlled cells (05-29-2024, 05:42 AM)InsiteFX Wrote: View Cells must return a string not an int. As far as I can see, the Cell is returning a string, because it's returning the content of just_a_test.php. But for the sake of the conversation, here is the modified version, returning the same error, which is: Code: Undefined variable $typedVariable Code: JustATestCell.php PHP Code: <?php Code: just_a_test.php PHP Code: <div> Code: main view file PHP Code: <?= view_cell('JustATestCell', [
Try:
PHP Code: class JustATestCell extends Cell PHP Code: class JustATestCell extends Cell This is due to the behavior of get_object_vars(). See https://www.php.net/manual/ja/function.g...php#127940
(05-30-2024, 05:21 AM)kenjis Wrote: Try: This was pretty cool, good job, many thanks, much appreciated! Could be useful then to use the Reflection API to improve this function? I mean CodeIgniter\Traits\PropertiesTrait->getPublicProperties(), instead of relying on get_object_vars() should leverage the advantages of the Reflection API over get_object_vars() |
Welcome Guest, Not a member yet? Register Sign In |