CodeIgniter Forums
Understanding View Cells - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=31)
+--- Thread: Understanding View Cells (/showthread.php?tid=78700)



Understanding View Cells - LeoKarun - 02-27-2021

Hello everyone!

I'm working on my first project on code igniter and found it quite promising so far. I've been going through the docs and came across View Cells, which seemed quite useful on the first glance. But after going through the entire documentation I found it a bit contradicting to the MVC pattern. 

On one hand, we are supposed to make calls to Views and Models only from a Controller class, but View Cells on the other hand, suggests that the method can be called from any class- even outside Controller. The doc mentioned an example that uses a function from a different class(not controller), querying data from a model and feeding the retrieved data to a view. Is it a good practice? Doesn't this approach break the MVC pattern? If someone could help clarify, it'd be really helpful. Cheers.


RE: Understanding View Cells - InsiteFX - 02-28-2021

The recommended way of using view cells is to place them into a Library.

The view cell methods in the Library can then interact with the model etc;


RE: Understanding View Cells - LeoKarun - 02-28-2021

(02-28-2021, 01:48 AM)InsiteFX Wrote: The recommended way of using view cells is to place them into a Library.

The view cell methods in the Library can then interact with the model etc;
Hey, thanks for responding. I take it that it is alright to interact with models even from outside controllers.