Welcome Guest, Not a member yet? Register   Sign In
How to load model and helper
#9

(07-22-2016, 12:34 PM)kilishan Wrote:
(07-22-2016, 12:10 PM)idealcastle Wrote: How might one "Auto-Load" a model?

Or, as for namespaces, I assume I cant add my "use \namespace;" and then call the model statically like Laravel? such as "ModeName::find(123)", seems repetitive to have to instantiate the class with "new Model()" and then call methods.

Nope - no calling it statically - unless you create static methods. FYI - Laravel's not really called static, either, but it sets up an intermediate layer called a Facade, that mimics it and handles creating an instance for you.

The best way to handle it is either load it in your controller's constructor, or have a base controller setup that loads the ones you want.

Thought, it's really not that much typing to say, "$model = new \App\Models\MyModel();" whenever you need it. That has the added benefit that anyone who comes after you that looks at your code knows exactly what the model is at a glance. Smile

Thanks. yeah I actually like that. I've been testing out CI4, building one of my new platforms off it (really would like to see how it handles).
Reply


Messages In This Thread
How to load model and helper - by HTLove - 07-18-2016, 06:55 AM
RE: How to load model and helper - by PaulD - 07-18-2016, 07:08 AM
RE: How to load model and helper - by HTLove - 07-18-2016, 07:27 AM
RE: How to load model and helper - by ciadmin - 07-18-2016, 08:00 AM
RE: How to load model and helper - by kilishan - 07-18-2016, 11:56 AM
RE: How to load model and helper - by idealcastle - 07-22-2016, 12:10 PM
RE: How to load model and helper - by HTLove - 07-18-2016, 06:25 PM
RE: How to load model and helper - by kilishan - 07-22-2016, 12:34 PM
RE: How to load model and helper - by idealcastle - 07-22-2016, 01:31 PM



Theme © iAndrew 2016 - Forum software by © MyBB