• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to load model and helper

#1
Hi All.
I want load model and helper and using it.
Can't you help me using it.
Tks all Heart
Reply

#2
http://bfy.tw/6nPe

Or http://www.codeigniter.com/user_guide/ge...lpers.html or http://www.codeigniter.com/user_guide/ge...odels.html
Reply

#3
i'm use CI4
Reply

#4
Models: https://bcit-ci.github.io/CodeIgniter4/d...model.html
Helpers: https://bcit-ci.github.io/CodeIgniter4/g...lpers.html
Reply

#5
Interestingly enough, the Models docs doesn't actually say how to load a model. Embarrassing. Smile But, a model is just a class, so you would get a new instance of it like you would any other class:

Code:
$model = new \App\Models\MyModel();

The helpers docs do explain.
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#6
Tks you very much
Reply

#7
(07-18-2016, 12:56 PM)kilishan Wrote: Interestingly enough, the Models docs doesn't actually say how to load a model. Embarrassing. Smile But, a model is just a class, so you would get a new instance of it like you would any other class:

Code:
$model = new \App\Models\MyModel();

The helpers docs do explain.



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.
Reply

#8
(07-22-2016, 01: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
Support Development  • Practical CodeIgniter 3  • Vulcan - CLI Tools for CI4
Reply

#9
(07-22-2016, 01:34 PM)kilishan Wrote:
(07-22-2016, 01: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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.