Welcome Guest, Not a member yet? Register   Sign In
Hi, I'm trying to learn, but I'm in trouble. I was wondering how to globally call the
#1

Hi, I'm trying to learn, but I'm in trouble. I was wondering how to globally call the functions of a library / model by declaring it only once.

I try to explain myself better, I declare the library that I need in the controller and in the controller itself I use it. So far everything is ok.
 
But if I need to use the same function directly in a View file, do I have to declare the library again? How can I optimize this?

*The concept is that of not always wanting to repeat the appeal of libraries or models.
Reply
#2

You don't need to declare it in the view just make the function in the controller and pass it to view as an atty of variable I guess.
Reply
#3

If your view need to call a model, then you’re doing something wrong. The view should only render html, not querying de database.

The only exception I can see is the view-cell in CI4 where you call a function from a library that do everything and return the final HTML code to be inserted in the parent view.
CodeIgniter 4 tutorials (EN/FR) - https://includebeer.com
/*** NO support in private message - Use the forum! ***/
Reply




Theme © iAndrew 2016 - Forum software by © MyBB