[answered] How to render cell passing variables to cell view? |
Hello
I have created this cell view in app/Cells PHP Code: <div class="card shadow"> and the respective controller in app/Cells PHP Code: <?php I'm reading the guide but I cannot find a suitable manner to pass those variables when it is time to view/render the cell I'd like to use something like PHP Code: <?= view_cell('SummaryCard1Btn::render', (passing here those 4 variables); ?> Can you kindly help with this? Thank you
Well, I ended up self answering my question
The guide is a bit messy in this chapter https://codeigniter4.github.io/CodeIgnit...cells.html, so for the sake of giving an hint to those that could sink (as I did) in that dis-order :-) here you an ordered example of How To Render a Cell View Passing It Variables for the Codeigniter's Guide Publisher I had to concentrate so much on the various parts of the guide and what I ended up to do is not written (if am I not wrong) in the guide - here https://codeigniter4.github.io/CodeIgnit...mple-cells it shown this code PHP Code: <?= view_cell('AlertMessage::show', ['type' => 'success', 'message' => 'The user has been updated.']); ?> - but then the show() method is used only in the simple cells where html strings are supposed to be returned and not a view file to be rendered (the topic of this post) - then here https://codeigniter4.github.io/CodeIgnit...olled-cell is used again the above alert message example, but this time without an hint on how to call the cell' view with the data passed to that view So, here it is an ordered example for the question expressed in this topic How to render a cell view passing variables to that cell view just to recall the alert message example of the guide, create the cell and the cell' view (note: with CodeIgniter 4.3+ this can be done altogether using a spark command in the terminal to be run in the root of the codeigniter app Code: #php spark make:cell MakeDivAlert so, either with spark or manually the following two files must be created /app/Cells/MakeDivAlert.php /app/Cells/make_div_alert.php (if you used the spark command, the view file must be renamed because of a bug, remove the string "_cell" from the filename) with the following content MakeDivAlert.php PHP Code: <?php make_div_alert.php PHP Code: <div> then in any view of your layout PHP Code: <?= view_cell('MakeDivAlert', ['type' => 'success', 'message' => 'The user has been updated.']); ?> NOTE: since MakeDivAlert has no methods in it, the first parameter in the view_cell() is just 'MakeDivAlert', without any call to any method . . |
Welcome Guest, Not a member yet? Register Sign In |